### Android(安卓)判断app的状态 重启app
16lz
2022-05-26
Android 判断app的状态 重启app
- 判断app的状态:
public int isBackground() { ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List appProcesses = activityManager .getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.processName.equals(getPackageName())) { if (appProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { //处于后台 return BACKGROUND; } else { //处于前台 return SHOW; } } } //被杀了 return KILL; }
- 重启app:
private void startApp() { Intent launchIntent = this.getPackageManager(). getLaunchIntentForPackage("包名"); launchIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); launchIntent.putExtra(RECEVIER_INTENT_MESSAGE, messge); startActivity(launchIntent); }
更多相关文章
- js判断运行平台
- Android下修改SeekBar样式
- android 把图片状态由彩色变成灰色
- Android(安卓)Service中判断系统全屏
- android canvas中的save()和restore()的作用及效果
- android listView 滚动加载显示
- android状态栏 高度
- Android(安卓)底部导航BottomNavigationView(非官方)
- Android将发送的短信插入数据库