Issue
I want to fetch some important data in onCreate
of my Application, and store them in the memory.
Can I assume the data I store in memory will be there? If the app get destroyed, can I assume onCreate
will always get triggered again?
Solution
From the documentation for onCreate
Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created.
If your application is killed in the background by the system, then it would have to call onCreate
again next time it is launched. As long as you re-initialize your static value in onCreate
each time it should be safe - assuming your application class would hold a reference to it to prevent it from being garbage collected.
You may also find this question useful regarding garbage collecting of static variables.
Answered By - Tyler V
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.