andorid app home 返回桌面之后app 重新打开,

2020-10-14  本文已影响0人  陈陈_04d0

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;

}

上一篇下一篇

猜你喜欢

热点阅读