is App Running via RunningTaskInfo - Android android.content.pm

Android examples for android.content.pm:App

Description

is App Running via RunningTaskInfo

Demo Code

import android.app.ActivityManager;
import android.content.Context;
import java.util.List;

public class Main{

    public static boolean isAppRunning(Context context, String packageName) {
        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> tasksInfo = activityManager
                .getRunningTasks(100);//from  w w  w  . j a  v a 2  s.c o m
        for (RunningTaskInfo info : tasksInfo) {
            if (info.topActivity.getPackageName().equals(packageName)
                    && info.baseActivity.getPackageName().equals(
                            packageName)) {
                return true;
            }
        }
        return false;
    }

}

Related Tutorials