2

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

  • Hey Ayush 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. What's the particular use case you need it for? – Saamer Jun 11 '20 at 05:33
  • If you use `ActivityManager.RunningTaskInfo.NumActivities`, you can get the count of activities, you cannot get all of running activities name, if you want to get the all of running acitivities, you should create a list, when a activity was display, then add it, if it executed the finish() method, you can remove this activity from this list. – Leon Jun 11 '20 at 06:32

1 Answers1

0

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.

Saamer
  • 4,687
  • 1
  • 13
  • 55