is Activity Front - Android Activity

Android examples for Activity:Activity Status

Description

is Activity Front

Demo Code


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

import android.content.Context;

import java.util.List;

public class Main {
    public static boolean isActivityFront(Context context, String className) {
        ActivityManager mActivityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> tasksInfo = mActivityManager
                .getRunningTasks(1);//from  w w  w. jav a 2  s.  com
        if (tasksInfo.size() > 0) {
            if (className.equals(tasksInfo.get(0).topActivity
                    .getPackageName())) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials