In Androidmanidest.xml <application android:name= "Com.chat.IM"//with the following class to be consistent android:allowbackup= "true" android:icon= "@drawable/qq_logo" android:label= "@string/app_name" android:largeheap= "true" android:th Eme= "@android: Style/theme.notitlebar" >com.chat.im.javapublic class im extends application{public static im im;// Singleton public void OnCreate () {super.oncreate (); im = this;} public static Boolean putstring (string key, String value) {sharedpreferences settings = im.getsharedpreferences (Key, MODE _private); Sharedpreferences.editor Editor = Settings.edit (); editor.putstring (key, value); return Editor.commit ();} public static string getString (String key) {sharedpreferences settings = im.getsharedpreferences (key, mode_private); Return settings.getstring (Key, "");}} The first time in the activity to save data im.putstring ("key", "123"); Take out the data im.getstring ("key");//Get the result of 123 now open a process service (Android: process= ":p Ush") takes out the data im.getstring ("key");//The result is 123 second time to save the data in the activity im.putstring ("key", "456 "); Remove the data im.getstring (" key ");//The result is 456 now open a process service (android:process=":p Ush ") to take out the data im.getstring (" key ");// The result is still 123 analysis, this is the previous process is not over, I in the service inside the OnDestroy () use System.exit (0) to end this process will not have this problem
The Application.getsharedpreferences value of Android under multi-process