Static variable loses value

I ran into the problem of a static variable that I use throughout my project (it contains some fields from the file). In some cases, a variable loses its value, not always. I read about the life cycle of a static variable that it loses value in three cases:

1) The class is unloaded.

2) The JVM is shutting down.

3) The process is dying.

So, I have a question: is it not enough to overwrite onResume actions and parse the file again and load the static variable again if it is null?

+5
source share
2 answers

static/globals, , Application. :

public class FooApplication extends Application {
    protected Bar myBar;

    public Bar getBar() { return myBar; }
    public void setBar(Bar bar) { myBar = bar; }
    ...
}

, , .

<application
    android:icon="@drawable/ic_launcher_noteit1"
    android:label="@string/app_name" 
    android:theme="@style/App_Theme"
    android:name="FooApplication" 
    android:debuggable="true">

(FooApplication) getApplication(). , . - singleton.

, onResume. onRetainNonConfigurationInstance()

+2

, -, reset . , , getMyVariable() setMyVariable(), .

+1

All Articles