is Top Activity In Name List - Android Activity

Android examples for Activity:Top Activity

Description

is Top Activity In Name List

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 isTopActivityInList(Context context,
            List<String> nameList) {
        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> tasksInfo = activityManager
                .getRunningTasks(1);/*  w  ww  . j  a va2  s .c  o  m*/
        if (tasksInfo != null && tasksInfo.size() > 0) {
            for (String classname : nameList) {
                if (classname == tasksInfo.get(0).topActivity
                        .getClassName()) {
                    return true;
                }
            }
        }
        return false;
    }
}

Related Tutorials