How to know which actives are present in xamarin android?? should i use ActivityManager.RunningTaskInfo.NumActivities

Viewed 134

i want to go particular activity that is already present. I dont want to call on create of particular activity f it is already present in backstack

and reorder and brought to front is calling on create

1 Answers

As I mentioned in the comments, it is possible to do but for 99% of the cases, if you need it, you are doing something wrong. Android navigation rules suggest using Fragments instead of Activities for navigation. So you can have a LoginActivity and then your UserActivity, but one ends and the other one starts, so you won't even have two.

I translated the Java code here for you, and you can check that thread for a really good description of the same problem from 9 years ago.

ActivityManager manager = (ActivityManager)Application.GetSystemService(ActivityService);

RunningTaskInfo task = manager.GetRunningTasks(10)[0];
System.Console.WriteLine("This is the base activity " + task.BaseActivity.ClassName);
System.Console.WriteLine(task.NumActivities);
System.Console.WriteLine(task.TopActivity);
System.Console.WriteLine(task.Description);

PS: You need GET_TASKS if you are supporting a version before Android API 21.

Related