get Running Task by package name - Android App

Android examples for App:Package

Description

get Running Task by package name

Demo Code


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

public class Main {

    public static boolean getRunningTask(Context context, String packageName) {
        ActivityManager am = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
        return !TextUtils.isEmpty(packageName)
                && packageName.equals(cn.getPackageName());
    }// w ww  .j  a va  2 s  .  c om
}

Related Tutorials