Reputation: 7417
In my Android application I extend the "Application" class and use it as a singleton. I set in there my "User" object so I can access it from everywhere. For some reason, that object gets null. I have put logs and see that nothing "sets" the object to null.
What I have noticed is that in the logs I print the "Application" object's Id (memory #) and when the user object gets null, the "Application" object has changed id (new instance for some reason?). But the rest of the stuff in the "Application" object are fine, only user has a problem.
Any ideas what could cause this? I guess out of memory or something? Any ideas on how to overcome this without having to do major changes (like adding an sqlite?)
Upvotes: 2
Views: 168
Reputation: 2781
Any ideas what could cause this?
Most likely your object was not used or linked, so the Android OS targetted it as disposable, and the garbage collector freed its memory allocation
Any ideas on how to overcome this without having to do major changes (like adding an sqlite?)
Without seeing your code, it may be hard to help, however keep the following guidelines:
1 - Keep a direct link to the resources you are currently using (so, adding a attribute that links to your original object is fine
Boolean isFatherObjectAlive = "Original Object"."flag";
2 - Keep a command executing or an instruction that makes direct usage of the singleton object
singletonObject.doSomething();
Upvotes: 1
Reputation: 247
It is commont in android, you have to check it for null values and load them again.
Upvotes: 1