使用如下封装方法:
public boolean findActivty(String calssname){
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(1);
if (list != null && list.size() > 0) {
ComponentName cpn = list.get(0).topActivity;
if (calssname.equals(cpn.getClassName()))
return true;
}
return false;
}
使用:
if ( findActivty("com.xxxx.xxx.Activity") ){
Log.d(TAG,"----com.xxxx.xxx.Activity正在运行---");
}else if(!findActivty("com.xxxx.xxx.Activity")){
Log.d(TAG,"----com.xxxx.xxx.Activity没有运行---");
}