Lifetime of a static variable in Android

android, java, static

Solution

Static variables are associated with a class and they will live as long as the class is in the memory,and destroy when class gets unloaded (which very rarely happens).

In Android you have seen that when we close any application it does not close completely, It remains in the recent application stack, That you can see by holding in the home button(On Most Devices).

Android itself kicked out those recent app when the other app needs memory

Problem

when I declare and initialize a variable as static in my main activity and the activity gets destroyed. Can I still access the content of the variable? For example to always access a AsyncTask which I store to this variable? What I want is to be able to access to it also after an orientation change.

Original source

Related problems