Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get application package name that currently showing activity

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?

like image 516
Ilya Gazman Avatar asked Dec 06 '25 16:12

Ilya Gazman


1 Answers

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.


like image 179
Gilad Haimov Avatar answered Dec 08 '25 07:12

Gilad Haimov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!