Android 判断app的状态 重启app

  1. 判断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;    }
  1. 重启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);    }

更多相关文章

  1. js判断运行平台
  2. Android下修改SeekBar样式
  3. android 把图片状态由彩色变成灰色
  4. Android(安卓)Service中判断系统全屏
  5. android canvas中的save()和restore()的作用及效果
  6. android listView 滚动加载显示
  7. android状态栏 高度
  8. Android(安卓)底部导航BottomNavigationView(非官方)
  9. Android将发送的短信插入数据库

随机推荐

  1. android ExpandableListView的下拉刷新实
  2. Android菜鸟日记15-传感器与摄像头
  3. Android(安卓)Action使用实例
  4. android适配器:ArrayAdapter
  5. SystemServer 分析
  6. Android(安卓)NDK学习(5)调用.so文件
  7. 深入浅出Android(安卓)Support Annotatio
  8. as报错
  9. Android删除Alarm的方法
  10. TextView添加Onclick点击无效没反应解决