To add to what Justin says, by not handling the onPause/onResume, you are basically hoping that Android itself does not shut your app down on its own. Android has the right, and it will at times shut your app down to reclaim memory for other apps. If this happens, your app starts fresh. HOWEVER, you can use some of the lifecycle methods, onSaveInstance I think it is (still haven't memorized it all yet), that will get called either when your app is paused (back/home keys pressed) OR Android shuts your app down to make room for other apps running. Either way, you can save "state" at that time, so that when the user switches back to your app either by the last tasks running "hold home" approach, or actually running your app again from the drawer, you will be passed in a Bundle, and from that you can determine if there is state saved, and if so load it up, update your models, redraw your screen so that it looks as if the user never left your app.
You MUST implement these methods if you have any reason for your app to potentially resume where a user left off. There is never a guarantee that data they entered, for example, will still be in a field when they come back to your app. Another issue, if you don't handle it right, is if they change screen orientation by rotating their device. I believe Android stops your app and restarts it so it can redraw with the new orientation. There is a way to handle that tho so that your app doesn't shut down. Either way, it's similar to when your app is paused or Android shuts it down. You either disable that ability so your app is always long from (top to bottom long ways), or you handle it and reload your state data. On Tue, Jan 26, 2010 at 1:08 PM, Justin Anderson <[email protected]>wrote: > Read up a bit about the lifecycle of apps... > http://developer.android.com/guide/topics/fundamentals.html#actlife > > Pressing home does not shut down your app.... It causes Android to pause > it. Then when you launch it again the default behavior is to then resume > the app where it left off. You can change the bevavior of this with > different settings in the manifest file... I think you would be interested > in either the finishOnTaskLaunch or launchMode options (or both)... > > http://developer.android.com/guide/topics/manifest/activity-element.html > > Hope that helps, > Justin > > ---------------------------------------------------------------------- > There are only 10 types of people in the world... > Those who know binary and those who don't. > ---------------------------------------------------------------------- > > > > On Fri, Jan 22, 2010 at 8:04 PM, Alexander Paschenko < > [email protected]> wrote: > >> Hi all. >> I'm experiencing kind of strange behavior of my application after hard >> Home button is pressed. >> When you press Home, everything is OK - my app goes to the background, >> showing Home screen. But if you try to choose my app in the main menu >> or in the list of last tasks it behaves like it was not started before >> and does not show the last activity you were on - it just starts from >> scratch, namely, shows the splash screen and . Moreover, old >> activities of this app remain on the activities stack, and previous >> instance of the app is not terminated - so if you press Back for a few >> times you'll just run into those activities which were undoubtedly >> started during the previous session of work with my app. Splash screen >> is filtered by "android.intent.action.MAIN" filter and >> "android.intent.category.LAUNCHER" category. >> The strange thing is that all of that happens despite the fact that I >> do not intercept any Back key hits, or override any onPause or >> onResume methods. What's happening contradicts with my understanding >> of Android app lifecycle - I was sure that when you hit Home an app >> just goes to the background, and when you choose it in the menu later >> - it just unwinds and does not start anew. (Of course, unless stuff >> like that is stated in the app manifest or corresponding methods are >> overridden or something else). >> I hope you will be able to help me. Any advice on what to pay >> attention to or where to search for solution would be really great. >> >> Regards, Alex >> >> -- >> You received this message because you are subscribed to the Google >> Groups "Android Beginners" group. >> >> NEW! Try asking and tagging your question on Stack Overflow at >> http://stackoverflow.com/questions/tagged/android >> >> To unsubscribe from this group, send email to >> [email protected]<android-beginners%[email protected]> >> For more options, visit this group at >> http://groups.google.com/group/android-beginners?hl=en >> > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > > NEW! Try asking and tagging your question on Stack Overflow at > http://stackoverflow.com/questions/tagged/android > > To unsubscribe from this group, send email to > [email protected]<android-beginners%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-beginners?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en

