开发者

Position of the activity in the activity stack

开发者 https://www.devze.com 2023-02-12 02:07 出处:网络
Am having an applications which contains activity A,B,C and activity A has been launched from the launcher and B from A and C from B. Now am having a button in C on clicking the button i should tell t

Am having an applications which contains activity A,B,C and activity A has been launched from the launcher and B from A and C from B. Now am having a button in C on clicking the button i should tell the开发者_高级运维 position of the activity c in activity stack . Ex A-B->C means C is at the 3 position of the activity stack.. How could i find this ?

Thanks in advance.


There is no other way to know this, because of how the Tasks are designed. See this and this So a solution could be to keep track of the activities by storing them in an array of activities. I hope this helps.


Use ActivityManager to get the stack position of activity which u want

May use the following example code

ActivityManager mngr = (ActivityManager) getSystemService( ACTIVITY_SERVICE );

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

to get the position of activity which u want use the below code for ur requirement

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

and position start from o(zero).

Hope this will help you.


This is possible.

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

Android global variable

You then declare a variable within this class:

      public static int count = 0;

Then within each class you have

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

 }

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

You then know what position you are at all the time.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号