Android detects activity is at the top of the history stack

From the parent activity class, you still need to find out if the child is at the top of the story stack. I need to execute an action in all my actions in onPause, but only if the action is executed onPause, and this is the top activity. This can happen if the user clicks the Home button, but not when the action launches a new action and thus calls its own onPause. Any ideas would be great.

thank

+1
source share
1 answer

ActivityManager includes a getRunningTasks () method that will provide you with all current active tasks: Return a list of tasks that are currently being executed, with the last of them being the first and oldest in order. Please note that “starting” does not mean that any of the task codes is currently loaded or activity - the task could be frozen by the system so that it could be restarted in the previous state when the next one appeared in the foreground.

The returned data is a list of ActivityManager.RunningTaskInfo , each of which includes a ComponentName to get the activity that it represents.

+5
source

Source: https://habr.com/ru/post/1727903/