android - (清空缓存并 )重新加载app (关掉所有Activity, 打开MainActivity )

访问量: 197

参考: https://stackoverflow.com/questions/14001963/finish-all-activities-at-a-time

使用 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);

订阅/RSS Feed

Subscribe

分类/category