android 重启自身app
方法一:
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,也可能是我的做法不对,有兴趣的朋友可以试试,同时,欢迎大家给出更好的方法。
更多相关文章
- 浅谈Java中Collections.sort对List排序的两种方法
- Python list sort方法的具体使用
- python list.sort()根据多个关键字排序的方法实现
- android WIFI的一些属性
- Android(安卓)Service分析
- android中drawable转bitmap的两种方法
- Android(安卓)子线程 更新 UI 界面 总结
- android的activitygroup使用
- Android三种实现定时器的方法