I have created an android app in which i'm using an application class to store and access the global variables. But i came across a strange behavior that all the variables in my application class gets uninitialized in the following scenarios,
- if my app is idle for sometime(say 10 minutes or so).
- if my app goes to background (if a browser gets opened above the app).
I searched a lot in SO and web and doesn't found any suitable answer. AFAIK once application class is initialized it will be accessible for the lifetime of the application. Am i missing something here?
Since i'm new to android development i may be doing something wrong here. Can anyone point me to the right direction?...Thanks in advance.
public class MyApp extends Application {
private MyClass classObj = new MyClass();
private boolean flagOne = true;
private boolean flagTwo = false;
void setFlagOne(boolean flag) {
flagOne = flag;
}
boolean getFlagOne() {
return flagOne;
}
void setFlagTwo(boolean flag) {
flagTwo = flag;
}
boolean getFlagTwo() {
return flagTwo;
}
void setMyClassObj(MyClass obj) {
classObj = obj;
}
boolean getMyClassObj() {
return classObj;
}
}