The official documentation describes tasks as follows:
*All the activities in a task move together as a unit. The entire task (the entire activity sta
That will not work. Your activity could get an onPause for reasons other than your app explicitly starting another activity. For instance, the user could have hit the back button, taking you back to a previous Activity in your stack.
public boolean isCurrentTaskInBackground() {
List<RunningTaskInfo> taskInfoList = mActivityManager.getRunningTasks(1);
if (taskInfoList != null && taskInfoList.size() > 0) {
RunningTaskInfo info = taskInfoList.get(0);
ComponentName componentName = info.baseActivity;
MobileTvLog.debug("App#isCurrentTaskInBackground -> baseActivity = " + componentName);
String packageName = componentName.getPackageName();
return !YOUR_PKG_NAME.equals(packageName);
} else {
return true;
}
}