I´ll do appreciate som light with the following problem.
I am writing an android application that comunicates with a remote server, the application stars with a login scrren, after the user login i want some important ionformation to get reachable through the entire appLication, user information, the department in wich the user works etc,
After reading about the best to achieve that I decided to use a singleton by extending the application class. Here is an example.
public class UsuarioCustom extends Application {
private Usuario usuario;
private Location posicionActual;
private Delegacion department;
private RutaCustom rutaActual;
//getters and setters ....
}
One of the requirements of the applications is that have to send the current location of the user ever 10 minutes so this application needs to keep running for a log while.
I am testing the appication and from time to time crashed showing the window the application has stoped.
I debuged de application and I realized the at some point android set my singleton class to null. I read on the web that this is a common issue in android…
For example If i start my application then with the phone to airplane mode and then come back to my app y can see how my singleton is null.
I have read on the web about singleton classes on android, some people says that is better to use a servive but seems like the oficial android sdk documentation lacks some useful information here.
I am thinking about saving the information on sqllite so every time i want to use my singleton class i check if is null, if so i reload it again from sql litte.
Can someone give some nice tips about the best way to deal with that probem??.
Thanks a lot.
After searching the web , I finally decided to save the important imformation on the sqllite. Seems like in an Android enviroment u can not trust that u can save data on memory for a long time, soon or later Android will delete the informatión even if you create a singleton by extending the Application class.