Search code examples
androidlifecycle

Is ApplicationData safe place to store data during onPause?


In my application I'm storing all data in ApplicationData so that it can be easily shared between activities. My understanding is that this data should persist for the full life cycle of the application from the initial onCreate to the final onDestroy. That being the case, is there any need for me to store data in persistent storage during the onPause of all but the top activity?


Solution

  • My understanding is that this data should persist for the full life cycle of the application from the initial onCreate to the final onDestroy.

    Not exactly. Your process and custom Application class will remain around as long as Android lets it. Android may terminate the process outright to free up memory in an emergency. Not to mention that battery-powered devices may have their batteries go dead.

    That being the case, is there any need for me to store data in persistent storage during the onPause of all but the top activity?

    Only if you don't want the data. Use Application (or static data members) as a cache only.