Delete SharedPreferences File

后端 未结 4 1974
南方客
南方客 2020-12-05 05:21

I am allowing the user to create multiple SharedPreferences files, but I also would like the option for them to delete these files. I know I could use internal

4条回答
  •  悲哀的现实
    2020-12-05 06:06

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        context.deleteSharedPreferences(preferencesKey);
    } else {
        try {
            org.apache.commons.io.FileUtils.cleanDirectory(new File(context.getCacheDir().getParent() + "/shared_prefs/"));
        } catch (IOException e) {
            Log.e(TAG, "Cannot delete files in shared pref directory", e);
        }
    }
    

提交回复
热议问题