is App Running Top - Android App

Android examples for App:App Running

Description

is App Running Top

Demo Code


//package com.java2s;

import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;

import android.content.Context;

public class Main {

    public static boolean isAppRunningTop(Context context) {

        ActivityManager am = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> list = am.getRunningTasks(1);
        if (list.size() > 0) {
            String packageName = context.getPackageName();
            RunningTaskInfo topRunningTaskinfo = list.get(0);
            if (topRunningTaskinfo.topActivity.getPackageName().equals(
                    packageName)) {//from   w ww . j  a  v  a 2s  .com
                return true;
            }
        }

        return false;
    }
}

Related Tutorials