方法一:     

public static void reStartApp()
     {
        Intent intent = new Intent(s_inst, SplashActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        s_inst.startActivity(intent);
        android.os.Process.killProcess(android.os.Process.myPid());
     }

在setFlag 的时候,有的set为 FLAG_ACTIVITY_CLEAR_TOP, 至于两者的区别,这里有篇文章,有兴趣的朋友可以看下:https://blog.csdn.net/weixin_38801333/article/details/76846311

方法二:

Intent intent = getBaseContext().getPackageManager()
                .getLaunchIntentForPackage(getBaseContext().getPackageName());
         PendingIntent restartIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
        AlarmManager mgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, restartIntent); // 1秒钟后重启应用
        System.exit(0);

除了两者之外,还有一篇感觉是比较合理的,链接如下:https://www.jianshu.com/p/6321c7bfb443。 不过,我参照这种方法做的时候,有时候不会重启App,也可能是我的做法不对,有兴趣的朋友可以试试,同时,欢迎大家给出更好的方法。

更多相关文章

  1. 浅谈Java中Collections.sort对List排序的两种方法
  2. Python list sort方法的具体使用
  3. python list.sort()根据多个关键字排序的方法实现
  4. android WIFI的一些属性
  5. Android(安卓)Service分析
  6. android中drawable转bitmap的两种方法
  7. Android(安卓)子线程 更新 UI 界面 总结
  8. android的activitygroup使用
  9. Android三种实现定时器的方法

随机推荐

  1. android添加新驱动
  2. 实现调用android URLConnection封装后快
  3. android 核心组件( 1 ) 常用布局, adapte
  4. Android中利用GridView实现水平和垂直均
  5. Android release版本apk添加数字签名
  6. android如何配置基本环境
  7. Android时区问题
  8. Android(安卓)wifi热点创建和自动连接
  9. Android调用系统自带的文件管理器进行文
  10. 《疯狂Android讲义》学习笔记二