is Top Activity In Task - Android Activity

Android examples for Activity:Top Activity

Description

is Top Activity In Task

Demo Code


//package com.java2s;

import android.app.ActivityManager;

import android.app.ActivityManager.RunningTaskInfo;

import android.content.Context;

import java.util.List;

public class Main {

    @SuppressWarnings("deprecation")
    public static boolean isTopActivityInTask(Context context,
            String className) {// www  .j  a va  2s.  c  o m
        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> tasksInfo = activityManager
                .getRunningTasks(1);
        if (tasksInfo != null && !tasksInfo.isEmpty()) {
            if (className.equals(tasksInfo.get(0).topActivity
                    .getClassName())) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials