Android: Restoring the active Activity while resuming the application?

EDIT : Found the solution to your problem somewhat randomly today! See this error report It explains your problem exactly. The reason I couldn't reproduce the problem is I never have Eclipse launch an app directly.

I use Eclipse to install the app and then start it myself This is already the default behavior for Android applications, no special tricks are required to achieve this. I'm surprised your application isn't demonstrating this behavior. Every Android application maintains an Activity stack, literally a LIFO stack of activities.

These activities can be further grouped into tasks, but 99% of mundane apps won't ever need to know anything about tasks in my experience When you press the home button, the entire application stack is put into the background. While in the background, it may be killed for memory concerns at any time, but if not much time elapses before it is restored, it generally isn't killed and doesn't have to be recreated. When you select the application again, the stack (or more accurately, only the top item on the stack) is restored If your application isn't exhibiting this behavior, I suspect it has something to do with how you are starting the mainActivity and childActivity and any extra Intent flags you may be using.

Any chance you can post code snippets on how you are starting the mainActivity and childActivity?

EDIT: Found the solution to your problem somewhat randomly today! See this error report. It explains your problem exactly.

The reason I couldn't reproduce the problem is I never have Eclipse launch an app directly. I use Eclipse to install the app and then start it myself. This is already the default behavior for Android applications, no special tricks are required to achieve this.

I'm surprised your application isn't demonstrating this behavior. Every Android application maintains an Activity stack, literally a LIFO stack of activities. These activities can be further grouped into tasks, but 99% of mundane apps won't ever need to know anything about tasks in my experience.

When you press the home button, the entire application stack is put into the background. While in the background, it may be killed for memory concerns at any time, but if not much time elapses before it is restored, it generally isn't killed and doesn't have to be recreated. When you select the application again, the stack (or more accurately, only the top item on the stack) is restored.

If your application isn't exhibiting this behavior, I suspect it has something to do with how you are starting the mainActivity and childActivity and any extra Intent flags you may be using. Any chance you can post code snippets on how you are starting the mainActivity and childActivity?

You are right. After I signed my test application and install it to G1 and run, I saw the correct behavior I am expecting to see. The next I am going to do is to clean my code from save/restore states and rerun on my device.

Thank you very much for your help. :) – Omer Apr 9 '09 at 5:57 Soonil, I want to ask you non related question. Do you use automated script to build and export your application?

If so, how do you do that? I couldn't figure out the exporting specifically for android. Thank you.

– Omer Apr 12 '09 at 15:06 I've considered moving to use ANT to build with, but at the moment Eclipse does everything I need. I just use a few scripts to make signing an app a bit easier. You can find a pretty good explanation of a simplified release process at developer.android.Com/guide/publishing/app-signing.

Html – Soonil Apr 13 '09 at 19:15 Thank you so much for your post and edit Soonil, I've been scouring the web and the android application fundamentals for about an hour trying to figure out why my app wouldn't keep it's state on a subsequent launch. The behavior I am experiencing is spelled out exactly in that bug report. – Austyn Mahoney Mar 8 '10 at 22:53.

Check how I workarounded this - github.com/cleverua/android_startup_acti....

I went back and tested with a similar application, and even when the process is forced out of memory the ChildActivity is reconstituted automatically as Soonil says. Are you seeing this on the emulator or on an actual device? If you run your app and watch logcat, you should see something like the following after you launch your App, then open the ChildActivity and click Home and then launch your activity again: Starting activity: Intent { action=android.intent.action.

MAIN categories={android.intent.categroy. LAUNCHER} flags=... comp={com.yourpackagename. MainActivity} } Start proc for activity yourpackagename.

ChildActivity: pid=x uid=y gids={} Displayed activity /. ChildActivity Could you post the output of logcat when you do not see the behavior you expect?

AFAIK this is inaccurate. When a process is killed and it's Activities are restarted the activity stack is saved. Each activity must serialize information only about it's own state.

State of the overall activity stack is maintained by the system. (I'll remove my downvote if you can link me to proof) – Soonil Apr 8 '09 at 13:49.

This is already the default behavior for Android applications, no special tricks are required to achieve this. I'm surprised your application isn't demonstrating this behavior. Every Android application maintains an Activity stack, literally a LIFO stack of activities.

These activities can be further grouped into tasks, but 99% of mundane apps won't ever need to know anything about tasks in my experience. When you press the home button, the entire application stack is put into the background. While in the background, it may be killed for memory concerns at any time, but if not much time elapses before it is restored, it generally isn't killed and doesn't have to be recreated.

When you select the application again, the stack (or more accurately, only the top item on the stack) is restored. If your application isn't exhibiting this behavior, I suspect it has something to do with how you are starting the mainActivity and childActivity and any extra Intent flags you may be using. Any chance you can post code snippets on how you are starting the mainActivity and childActivity?

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