We're designing an Android app that has several activities which are working in a wizard like way - user should pass from the activity #1 to activity #5 to get to the final activity (#6).
Since we know an activity can be suddenly terminated by OS on low memory we used Application class as a static storage for keeping the data the user inputs on "wizard" activities and other data our app needs for the whole session.
Unfortunately we've discovered this approach fails - looks like the Application class instance is also can be killed by OS (this was specifically discovered on Android 1.6 versus 1.5). Are our expectations wrong on this approach (we think Application class instance always lives for the whole app session)?
So the question is - what is the best practices on Android to keep data between activities deathes/restarts for the whole application session?
We're designing an Android app that has several activities which are working in a wizard like way - user should pass from the activity #1 to activity #5 to get to the final activity (#6).
Are you sure you should be implementing them as separate activities? Why not a single activity, using ViewFlipper
or something to move between the wizard states?
Are our expectations wrong on this approach (we think Application class instance always lives for the whole app session)?
The Application class instance does always live for the whole app session, AFAIK. Once all your activities are destroyed, though, the Application will be destroyed as well.
So the question is - what is the best practices on Android to keep data between activities deathes/restarts for the whole application session?
Service
-- if this gets kicked out of RAM, just start over from scratchOr, best: don't use multiple activities in this case. A wizard is a single logical thing; treat it as such and make it be a single activity. Persist your state via onSaveInstanceState()
, and you're set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With