I found a workaround, but it's a hack, so I'm still open for better
ideas. I found this to do exactly what I need:
in the main activity of my app:
@Override
protected void onPause() {
super.onPause();
ActivityManager am = (ActivityManager) getSystemService
(ACTIVITY_SERVICE);
List<RunningTaskInfo> taskInfo = am.getRunningTasks(1);
if (!taskInfo.isEmpty()) {
ComponentName topActivity = taskInfo.get(0).topActivity;
if (!topActivity.getPackageName().equals(getPackageName
())) {
// disable listeners ...
}
}
}
what this does is find out what the most recently triggered activity
is when the current activity is paused (i.e., it yields the name of
the activity that caused the pause, e.g. the home app), and checks
whether it's an activity of the same package or not (in the latter
case, I unregister the listeners to save battery life).
An app.onPause() hook or a simple isApplicationVisible() would be a
lot nicer of course...
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---