At the first launch of the application in the root activity, the user must select certain parameters that determine what data will be downloaded for him from the database.
As soon as he selected this option, the data is loaded and stored in a singleton class, which should store this data while the application is running. (Even in the background)
My problem is that sometimes when a user exits my application for some time (using the home button), Android seems to kill some actions in my application, and somehow with them it resets the important singleton class. Due to the fact that my application receives all kinds of null reference exceptions as soon as I try to access the data that should be stored in a singlet.
I understand that the Android OS can sometimes kill an application, but allows the user to return to it from their last attended event. Sometimes it just kills the whole application and forces the user to start from the very beginning.
I was looking for a solution, and I found out about the android: alwaysRetainTaskState attribute, which I can apply to my activity. Obviously, with this, when android decides to kill my application, it will at least force the user to start with the first action, where I can reload the data, instead of allowing the user to start with more advanced activities, forcing him to get null exceptions.
However, when I applied it in my application, it did not work, and when I returned to my application, I started with the extended action with an empty singleton instance.
I also tried "android: clearTaskOnLaunch" and it worked, but it’s overkill, since I don’t want every time the user comes back to the application, he had to start all over again. I want this to happen only if Android decides to kill the application.
-, ? , , ?
!