What is the best Android practice for storing data between actions or restarts for an entire application session?

We are developing an Android application that has several actions that work in the wizard, for example: the user must go from action No. 1 to action No. 5 in order to proceed to completion (# 6).

Since we know that activity can be suddenly terminated by the OS on low memory, we used the Application class as a static storage for storing data that the user enters into the wizard actions and other data that our application requires for the entire session.

Unfortunately, we found that this approach fails - it seems that an instance of the application class can also be killed by the OS (this was specifically discovered in Android 1.6 vs. 1.5). Are our expectations wrong for this approach (we believe that an instance of the application class always lives on for the entire application session)?

So the question is, what is the best way to use Android to store data between actions / restarts for the entire application session?

+6
android android-activity architecture session
source share
2 answers

We are developing an Android application that has several types of activities that work in the wizard as a way - the user must switch from activity No. 1 to activity No. 5 in order to get to the finals (# 6).

Are you sure you should perform them as separate actions? Why not one activity using ViewFlipper or something to move between wizard states?

Are our expectations erroneous in this matter? approach (we believe that the application class instance always lives for the whole application session)?

An instance of the application class always runs for the entire AFAIK application session. However, if all your actions are destroyed, the application will also be destroyed.

So the question is, what is the best practice on Android for storing data between actions / restarts for an entire application session?

  • Use Service - if it comes out of RAM, just start from scratch
  • Use database
  • Use file

Or, best of all: do not use several actions in this case. The master is the only logical thing; consider it as such and make it one action. Transfer your state with onSaveInstanceState() and you will set.

+9
source share

If the data that the user enters and you need to save is just a set of primitives, you can simply use SharedPreferences as a persistent store.

0
source share

All Articles