YiiWang

Android实现APP重启功能
1.使用 FLAG_ACTIVITY_CLEAR_TOPIntent i = getBaseContext().g...
扫描右侧二维码阅读全文
30
2018/05

Android实现APP重启功能

1.使用 FLAG_ACTIVITY_CLEAR_TOP

Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());  
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  
startActivity(i);  

2.使用 AlarmManager

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() + 50, restartIntent);   
android.os.Process.killProcess(android.os.Process.myPid());  
Last modification:May 30th, 2018 at 09:22 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment