For storing runtime data in my app I have a class with two static variables:
public class App {
public static ClementineConnection mClementineConnection = null;
public static Clementine mClementine = null;
}
Those are initialized in the onCreate
Method of the first Activity. This Activity does nothing but starting other activities depending on a state (is the app connected to server).
If the App is idle or running in the background with a notification, sometimes a NullPointerException occurs in the other onCreate Methods when accessing one of the static variables. Somehow they get garbage collected. The App has a Service with a Thread running in the Background, so I thought there must be a reference all the time.
Do you know how I can prevent those static variables from being garbage collected? While the app is connected to the server, the information must be available. Creating a new instance (eg. Clementine.getInstance()
) is not an option.
If you want to have a look at the code: https://code.google.com/p/clementine-remote-android/source/browse/