如何判断Activity是否在运行
答案:2 悬赏:0 手机版
解决时间 2021-02-15 23:22
- 提问者网友:箛茗
- 2021-02-15 10:27
如何判断Activity是否在运行
最佳答案
- 五星知识达人网友:平生事
- 2021-02-15 11:30
判断android activity是否运行(可见)方法如下:
public static boolean isActivityRunning(Context mContext,String activityClassName){
ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
List info = activityManager.getRunningTasks(1);
if(info != null && info.size() > 0){
ComponentName component = info.get(0).topActivity;
if(activityClassName.equals(component.getClassName())){
return true;
}
}
return false;
}
public static boolean isActivityRunning(Context mContext,String activityClassName){
ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
List
if(info != null && info.size() > 0){
ComponentName component = info.get(0).topActivity;
if(activityClassName.equals(component.getClassName())){
return true;
}
}
return false;
}
全部回答
- 1楼网友:执傲
- 2021-02-15 12:30
判断android activity是否运行(可见)方法如下: public static boolean isactivityrunning(context mcontext,string activityclassname){ activitymanager activitymanager = (activitymanager) mcontext.getsystemservice(context.activity_service); list<runningtaskinfo> info = activitymanager.getrunningtasks(1); if(info != null && info.size() > 0){ componentname component = info.get(0).topactivity; if(<span style="font-family: arial, helvetica, sans-serif;">activityclassname</span>.equals(component.getclassname())){ return true; } } return false; }
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯