http://my.oschina.net/zhibuji/blog/195097
Main solution: In Android, multiple processes to modify the same sharedpreference, there will always be a process to obtain the results are not real-time modified results. Sharedpreference as one of the most convenient use of Android five storage (network, database, file, Sharedpreference,contentprovider), from the class name is not a tool to store big data, with key /value in pairs to store the base data type, only the base data type. Files stored in/data/data/your packagename/the Shared_prefs directory. The file storage format is as follows:<?xml version= '1.0' Encoding= ' utf-8' standalone= ' yes '? ><map><boolean name= "Key" value= "true"/><stringName= "Key" >hello</string></map>The best place to use sharedpreference is to keep the configuration information, and the data store in Android with a preference-specific preferencefragment is also stored using sharepreference, the default file name is ( Your packagename) _preferences.xml. If you want to modify the default file name, you can do so by using Getpreferencemanager () in preferencefragment. Setsharedpreferencesname ("Modify_default_ Preference ") to change the default file name. None of this matters. It is important to modify the same value in a multi-process problem. To facilitate the description, the process of creating a sharedpreference XML for the first time is described as the primary process, and the second process that uses the XML file is the different processes seen in the DDMS, including the different applications (Shareduid is also in the same), The secondary process generated by the process configuration in the same application. The communication between them will cause the main process to modify the value, which is read by the secondary process when it is initialized the first time. Currently there is no good solution on the network, my solution is as follows:1First, the MODE to get Sharedpreference is set to: Mode_multi_process. Its value is 4 (2.3 has this attribute later). such as: Getsharedpreferences ("Test_aa", mode_multi_process);. If this mode is used with Mode_private, then the value written in the other process will not be written to the file. 2, second, in order to ensure that the modified data submitted to disk in real-time, do not set sharedpreference to member variables, as far as possible where to modify the direct access to sharedpreference, modified do not forget the commit. If the above two points, no accident, the data can be modified in real time. If for convenience already wrote Sharedpreference editor of Tool class, then 2nd Basic can't do, so, need to do third step. 3, if two processes need to be read at a timely or logical operation based on this value, it is best to perform the editor operation in two processes. You can use service and AIDL technology, AIDL for this basic type of delivery so easy.
Sharedpreference multi-process data sharing error in Android