is Top Activity - Android Activity

Android examples for Activity:Top Activity

Description

is Top Activity

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 isTopActivity(Context activity, String packageName) {
        ActivityManager activityManager = (ActivityManager) activity
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> tasksInfo = activityManager
                .getRunningTasks(1);//from   w w  w .j  a v a2s.  co m
        if (tasksInfo.size() > 0) {

            if (packageName.equals(tasksInfo.get(0).topActivity
                    .getPackageName())) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials