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);
精彩评论