Skip to content Skip to sidebar Skip to footer

Get Current Visible Activity To User

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

Solution 1:

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.


Post a Comment for "Get Current Visible Activity To User"