This is true. However, my application, which comprises many activities, is the one starting (most) activities not started by the HOME key, which can't be intercepted (googling "android intercept home key" will bring up multiple discussions of this). I would prefer not to have my app needlessly hammer the system every time it starts up one of its own activities.
For now, I'm going with the almost-good-enough approach of updating its (zero, one, or more) app widgets when the root task closes (in its onPause(): isFinishing() is true, would also use isTaskRoot() if the task weren't always rooted by the same activity). I think it would be helpful if the API provided Activity.isTaskSwitching() and/or Activity.isApplicationSwitching() and maybe something to tell when being killed by the OS (e.g. for memory) for use in onPause() so that an application can tell that it's losing control. On Oct 9, 12:36 pm, RichardC <richard.crit...@googlemail.com> wrote: > As I understand it you are right, you need to react to onPause in each > activity (see also onSaveInstanceState()). > > The reason behind this is an end-user Task can comprise more than one > Applicaton/Process with each Application consisting of more than one > Activity. > > To give a made up example (which may not be possible with the actual > Andoid code base): > > 1) End-user starts MyApp with MyActivity1 > > 2) In MyActivity1 the end-user selects somethings which starts > GoogleMaps / GoogleMapsActivity1 with some push pin data from MyApp. > > 3) End-user selects on of the push-pins that causes Google Maps to > start MyActivity2 (in MyApp). > > So now we have > > MyApp MyActivity > GoogleMaps GoogleMapsActivity1 > MyApp MyActivity2 > > 4) MyApp/MyActivity2 could now display a web page etc. > > Any Application/Process which is not the current forground Activity is > a candidate to be killed by the OS if resources get tight. So each > Activity that pauses needs to save its state so that when the end-user > presses the back key it can restore itself and resume where it left > off. > > -- > RichardC > > On Oct 9, 6:22 pm, David Bernstein <dbb.post...@gmail.com> wrote: > > > How can an application detect when it's lost control of the screen? > > The reason I ask is that my application has an appwidget whose visible > > state should be consistent with user actions within the application. > > In addition to the application exiting, I'd like to know when other > > applications take over the screen. > > > Simply noticing in onPause() in the root activity isn't enough because > > the user can, for example, press the home key or receive a phone > > call. Noticing in onPause() in every single activity is overkill > > because the user will move between multiple activities in the same > > application. > > > If this is documented or discussed already, I'll humbly accept an RTFM > > pointer, but I didn't find anything when I looked. > > > Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---