In Android, use less static variables.
I am now doing an application in which the previous developer used static variables to store the cookie, a global static variable used to verify the identity.
At this point the customer response, the application for a long time not used, re-use, will prompt identity expired.
Later, the problem is basically determined on the static variable.
StackOverflow checked the life cycle of the static variable in Android, someone said
Lifetime of a static variable:a static variable comes into existence when a class was loaded by the JVM and dies when the Class is Unloaded,if-Create an Android application and initialize a static variable, it'll remain in the JVM until O NE of the following happens:
1. The class is unloaded
2. The JVM shuts down
3. The process dies
What happens in our application should be that the process is killed by the system.
Later, the situation was discovered, is to constantly open the application, when the system memory is not enough, the application process will be killed. When you open the app again, an identity expiration occurs, which is the case where the static variable is empty
Static variables, to use with caution!
Less static variables in Android (Static life cycle for Android)