Activity Position in Action Stack

I have applications containing actions A, B, C and activity A from the launcher and B from A and C from B. Now I have a button in C when I click the button, I have to indicate the position of activity c in the activity stack. Ex AB-> C means that C is in the 3rd position of the activity stack. How can I find this?

Thanks in advance.

+4
source share
3 answers

There is no other way to find out because of how Tasks are developed. See this and this. Thus, a solution may be to keep track of actions, storing them in an array of actions. Hope this helps.

+1
source

Use ActivityManager to get the activity stack position you want

You can use the following code example

ActivityManager mngr = (ActivityManager) getSystemService( ACTIVITY_SERVICE ); List<ActivityManager.RunningTaskInfo> taskList = mngr.getRunningTasks(10); 

to get the activity position you want to use the code below for ur request

 taskList.get(0).topActivity.getClassName() 

and the beginning of the position from o (zero).

Hope this helps you.

+1
source

It is possible.

What you need is an activity that extends the application. You also declare this in your manifest.

Android global variable

Then you declare a variable in this class:

  public static int count = 0; 

Then in each class you have

  @Override protected void onResume() { YourApplicationClass.count++; } @Override protected void onPause() { YourApplicationClass.count--; } 

Then you know what position you are in.

System.out.println ("Count is:" + YourApplicationClass.count);

0
source

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


All Articles