Inspect the highest activity in the left - Android android.app

Android examples for android.app:ActivityManager

Description

Inspect the highest activity in the left

Demo Code

import java.util.List;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.ComponentName;
import android.content.Context;

public class Main {

  public static boolean isTopActivity(String name) {
    ActivityManager activityManager = (ActivityManager) ContextUtil.CONTEXT.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> list = activityManager.getRunningTasks(1);
    ComponentName cn = list.get(0).topActivity;

    return cn.getClassName().equals(name);
  }/*from  w w  w. j  a  v  a 2 s  .co m*/

}

Related Tutorials