2

By using activityManager.getRunningTasks you can get the current running applications in android.
How ever it does not tell you which of those tasks activity is showing right now.

How do I get this information?

Community
  • 1
  • 1
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216

1 Answers1

1

To get topmost activity you will need to interrogate the first task returned by getRunningTasks:

ActivityManager activityManager = (ActivityManager)getSystemService(Activity.ACTIVITY_SERVICE);
RunningTaskInfo info = activityManager.getRunningTasks(1).get(0);
ComponentName topActivity = info.topActivity.getClassName();


BTW, the word is that getRunningTasks will be deprecated in Android L, so keep in mind.


Gilad Haimov
  • 5,767
  • 2
  • 26
  • 30