Lifetime Of Static Class Variables
public class Checker { static private int value1 = 0, value2 = 1; static private Activity activity; public static void init(Activity activity) { Checker.activ
Solution 1:
Based on the symptoms you are describing, what's most likely happening is that the ClassLoader for Checker is getting garbage collected but your Activity is not being garbage collected. So when the app returns from the background, Activity goes to onResume
. When the call to Checker.check()
is made, the Checker
class is reloaded with the default values of value1
and value2
.
One way to make sure that the Checker class stays around as long as the Activity is to keep a reference to a Checker instance in the Activity class. Of course, you might also consider redesigning the Checker functionality so that it doesn't depend on static member behavior.
Post a Comment for "Lifetime Of Static Class Variables"