is Running App - Android App

Android examples for App:App Running

Description

is Running App

Demo Code


//package com.java2s;
import android.app.ActivityManager;
import android.content.Context;

import java.util.List;

public class Main {
    public static boolean isRunningApp(Context context, String packageName) {
        boolean isAppRunning = false;
        ActivityManager am = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> list = am
                .getRunningTasks(100);/*www.  j a  v a  2 s .c  o m*/
        for (ActivityManager.RunningTaskInfo info : list) {
            if (info.topActivity.getPackageName().equals(packageName)
                    && info.baseActivity.getPackageName().equals(
                            packageName)) {
                isAppRunning = true;
                // find it, break
                break;
            }
        }
        return isAppRunning;
    }
}

Related Tutorials