onStop() and onPause() works great if your app only has one activity.
But they're also invoked if you switch to any sub activity, even if
it's done with startActivityForResult(). Only exception is when the
sub activity uses a transparent theme. (Well, onPause() is invoked for
sure, onStop() only sometimes...)
If you need a service that only runs when your app is visible, just
use a local service, Android will suspend it when the app becomes
invisible.
If you need to do something if the app is hidden, but not when
switching from one activity to another, there's no easy way I know of.
You can use "isFinalizing()" in onStop of the main activity, which
allows to do some work when the app is left with the back button. But
otherwise... Maybe with internal flags and handling the back button in
sub activities yourself, because without, you wouldn't know whether a
sub activity will return to the main activity (back button) or be left
to the Home screen or any other app (call, notification, etc.)...

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to