is Top Activity - Android android.app

Android examples for android.app:Activity Property

Description

is Top Activity

Demo Code

import android.app.ActivityManager;
import android.content.Context;
import java.util.List;

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);//  w  w  w . j  a v  a2  s. c o  m
        if (tasksInfo.size() > 0) {
            if (packageName.equals(tasksInfo.get(0).topActivity
                    .getPackageName())) {
                return true;
            }
        }
        return false;
    }

}

Related Tutorials