android - (清空缓存并 )重新加载app (关掉所有Activity, 打开MainActivity )
2017-08-25 12:04
访问量: 2299
分类:
技术
使用 finishAffinity() 方法即可.例如:
// 先清空缓存
SharedPreferences userSettings = getSharedPreferences("cache", MODE_PRIVATE);
SharedPreferences.Editor editor = userSettings.edit();
editor.clear();
editor.commit();
settings = App.application.getSharedPreferences(Constants.REFERENCE_NAME, 0);
SharedPreferences.Editor referEditor = settings.edit();
referEditor.clear();
referEditor.commit();
// 就是这一句.
finishAffinity();
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);