Public static variables and Android activity life cycle management

Posted by jsstp24n5 on Stack Overflow See other posts from Stack Overflow or by jsstp24n5
Published on 2012-08-30T03:33:38Z Indexed on 2012/08/30 3:38 UTC
Read the original article Hit count: 232

According to the documentation the Android OS can kill the activity at the rear of the backstack.

So, say for example I have an app and open the Main Activity (let's call it Activity A). In this public activity class I declare and initialize a public static variable (let's call it "foo"). In Activity A's onCreate() method I then change the value of "foo." From Activity A the user starts another activity within my app called Activity B. Variable "foo" is used in Activity B. Activity B is then paused after the user navigates to some other activities in other apps. Eventually, after a memory shortage occurs, Activity A then Activity B can be killed. After the user navigates back to my app it restarts (actually "recreates") activity B.

What happens: 1) Will variable "foo" at this point have the value that was set to it when Activity A's onCreate() method ran? 2) Variable "foo" does not exist? 3) Variable "foo" exists and but is now the initialized value and not the value set in Activity A's onCreate() method?

© Stack Overflow or respective owner

Related posts about java

Related posts about android