is Have Activity - Android android.app

Android examples for android.app:ActivityManager

Description

is Have Activity

Demo Code

import java.util.List;

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

public class Main {

  private static final String TAG = "SystemUtils";

  public static boolean isHaveActivity(String className, Context context) {
    boolean isHave = false;
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> activityList = am.getRunningTasks(100);
    if (!(activityList.size() > 0)) {
      return false;
    }/* w  w w.  j  av a2s .com*/
    for (int i = 0; i < activityList.size(); i++) {
      String topClassNameInfo = activityList.get(i).topActivity.getClassName();
      String baseClassNameInfo = activityList.get(i).baseActivity.getClassName();
      if (topClassNameInfo.equals(className) || baseClassNameInfo.equals(className)) {
        isHave = true;
        break;
      }
    }

    return isHave;
  }

}

Related Tutorials