Skip to content

Instantly share code, notes, and snippets.

@dcaoyuan
Created September 18, 2014 03:12
Show Gist options
  • Save dcaoyuan/199c098c7acd9e9a1639 to your computer and use it in GitHub Desktop.
Save dcaoyuan/199c098c7acd9e9a1639 to your computer and use it in GitHub Desktop.
private boolean isApplicationBroughtToBackground() {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment