I have an android app where I extend the application object as such
public class Globals extends Application {
private Map<String, Object> Creators = new LinkedHashMap<>();
}
Globals
has various things in it. usually HashMaps of things - I use it as a global json cache
where each Context
has an instance of this. Now overnight it appears the Application
object can sometimes be empty. i.e. I use the app go away and go to sleep, go back to testing it in the morning and all the json caches are empty. But the user is still "logged in". I assume this is because of garbage collection on the OS.
Now. I could just refresh the json cache
or force "logout" when the json cache
is empty but there is a problem - it may be empty because there IS legitimately no json from the server. i.e "being empty" is no reason to go get more. What I need to be able to do is detect when android has flattened the cache, or at least know the minimum amount of time that Android will keep the Application
extension.
Would it set everything to null
?
Has anyone got any ideas? Bear in mind the context will re-initialise null HashMap members of the Application
in the context in onCreate
(which is required for reason outside the scope) because I declare the new
but simply testing for "null" is not really an option. I suppose making a blank null that is changed only on json gather
would be ok but I need to KNOW this will work or I lose yet another day chasing this (i.e it's VERY hard to test)