我有一个需要从缓存中清除并以编程方式重新启动的应用程序。
我尝试过
Intent i = new Intent(this, MyActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
但这不会完全清除所有缓存,因为以某种方式检索了旧上下文。
通过这种方式,我设法实现了一个丑陋的解决方法,但如果有其他解决方案,我将感到高兴:
Intent mStartActivity = new Intent(this, MyActivity.class);
int mPendingIntentId = 1122;
PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId,
mStartActivity,PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarmMgr =(AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
// Set the alarm that will invoke and start the activity after we
// killed the current process
alarmMgr.set(AlarmManager.RTC, System.currentTimeMillis()+10, mPendingIntent);
// Kill the application process, this will for sure clear up all
// memory!
android.os.Process.killProcess(android.os.Process.myPid())