The Application.getsharedpreferences value of Android under multi-process

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.