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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With