How to save activity's state in android?

mobile.tutsplus.com/tutorials/android/an... Take a look at this tutorial about SharedPreferences or developer.android.com/reference/android/....

mobile.tutsplus.com/tutorials/android/an... Take a look at this tutorial about SharedPreferences or developer.android.com/reference/android/....

If you are talking about a case where another Activity interrupts the current one then you should look into managing the Activity lifecycle developer.android.com/guide/topics/funda... onSaveInstanceState(), onRestoreInstanceState() or in onPause() and onResume(). If this is for persistent data storage then SharedPreferences / DB or some other form of storage would be required: developer.android.com/guide/topics/data/....

This is a classic 'gotcha' of Android development. There is a subtle Android Framework bug which greatly complicates application stack management during development, at least on legacy versions (not entirely sure if/when/how it was fixed). I'll discuss this bug below.

Browsing across all these threads, I suspect that much of the time developers are talking about these two different issues simultaneously ... hence all the confusion and reports of "this doesn't work for me". First, to clarify the 'intended' behavior: onSaveInstance and onRestoreInstance are fragile and only for transient state. The intended usage (afaict) is to handle Activity recreation when the phone is rotated (orientation change).

In other words, the intended usage is when your Activity is still logically 'on top', but still must be reinstantiated by the system. The saved Bundle is not persisted outside of the process/memory/gc, so you cannot really rely on this if your activity goes to the background. Yes, perhaps your Activity's memory will survive its trip to the background and escape GC, but this is not reliable (nor is it predictable).

So if you have a scenario where there is meaningful 'user progress' or state that should be persisted between 'launches' of your application, the guidance is to use onPause and onResume. You must choose and prepare a persistent store yourself. BUT - there is a very confusing bug which complicates all of this.

Basically, if your application is launched with the SingleTask flag, and then later on you launch it from the home screen or launcher menu, then that subsequent invocation will create a NEW task ... you'll effectively have two different instances of your app inhabiting the same stack ... which gets very strange very fast. This seems to happen when you launch your app during development (i.e. From Eclipse or Intellij), so developers run into this a lot.

But also through some of the app store update mechanisms (so it impacts your users as well). I battled through these threads for hours before I realized that my main issue was this bug, not the intended framework behavior. I would greatly appreciate any corrections on this.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions