How to update SharedPreferences in android when recovering from a file?

I backup the xml SharedPreferences file to the SD card from the file

File taskExceptionFile = new File(Environment.getDataDirectory() + "/data/" + packageName + "/shared_prefs/" + TaskAction.SHARED_PREF_TITLE_TASK_EXCEPTION + ".xml"); 

however, when I restore the file if the file was opened

 SharedPreferences sp = context.getSharedPreferences(TaskAction.SHARED_PREF_TITLE_TASK_EXCEPTION, 0); 

before recovery SharedPreferences seems to have a cache, I use Root Explorer to view the file after recovery, the values ​​are really the values ​​from the backup file, but when I use

 sp.getInt(TaskAction.SHARED_PREF_TASK, 0) 

to get the value, the value is not a new value from the backup file, it returns the default value of 0. I force stop my application and reconnect to my application, the values ​​are the new values.

So, I want to ask how to update SharedPreferences right after restoring a file so that I can get a new value?

Sorry for my bad english ~~~

+6
source share

All Articles