if (!isTaskRoot()) {
// 判断当前activity是不是所在任务栈的根
Intent intent = getIntent();
if (intent !=null) {
//判断使用页面是否已经存在。
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(intent.getAction())) {
finish();
return;
}
}
}
/** 课外知识
* 判断服务是否在运行
*
* @param context
* @param serviceName
* @return 服务名称为全路径 例如com.ghost.WidgetUpdateService
*/
public boolean isRunService(Context context, String serviceName) {
ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceName.equals(service.service.getClassName())) {
return true;
}
}
return false;
}
网友评论