I want to get the foreground activity running. And I am able to get this information by using activity manager by using following code.
activityManager = (ActivityManager) FWCommon.getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
runningTaskInfoList = activityManager.getRunningTasks(1);
componentName = runningTaskInfoList.get(0).topActivity;
Suppose I have two activities A and B and i call this above code from onResume() of both activities A and B.
Following is the problem
Thx Dalvin
Try using getRunningAppProcesses() to get a list of RunningAppProcessInfo. Then go through each RunningAppProcessInfo and check if it is in the foreground by doing this:
List<ActivityManager.RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo process : processes)
{
// Take a look at the IMPORTANCE_VISIBLE property as well in the link provided at the bottom
if (process.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND)
{
// Put code here
}
}
Click here and here for more information.
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