0

Possible Duplicate:
Run code when Android app is closed/sent to background

In my android app I need to be notified when users switching from my app to any other app, in order to do some security jobs. It can be by tapping on Back, Home button, through Recent Apps button. Any other ways? Couldn't find anything in android.app.Application. I have many activities in the app, to put code in Activity.onPause() won't work because it may goes to another activity in the same app. I need to find a way to be noticed. Any good idea on this? Thanks

Community
  • 1
  • 1
brewphone
  • 1,316
  • 4
  • 24
  • 32

2 Answers2

3

Duplicate of: Run code when Android app is closed/sent to background

Basically - create a base activity with onPause set correctly and extend all other activities from that one.

Community
  • 1
  • 1
Matt Razza
  • 3,524
  • 2
  • 25
  • 29
0

AFAIK there is no easy way of doing what you need.

In our application we resort to polling current top activity, to check if it belongs to our application.

ComponentName getTopActivity() {
    List<ActivityManager.RunningTaskInfo> runningTasks = activityManager.getRunningTasks(1);
    ActivityManager.RunningTaskInfo topTask = runningTasks.get(0);
    return topTask.topActivity;
}

I would really like to know is there any better way.

uaraven
  • 1,097
  • 10
  • 16