Android Apidemos Sample resolution: App->preferences->launching Preferences

Source: Internet
Author: User

The previous example describes how to use Preferenceactivity to display modify application preferences, and the user's modifications to preferences are automatically stored in the corresponding Shared preferences of the application.

This example describes how to obtain a preference value by preferenceactivity from an activity. For example, in practical applications through the Preferenceactivity interface to obtain user preferences or configuration.

Because you want to return a value from preferenceactivity, you use Startactivityforresult to start the preferenceactivity derived class.

Advancedpreferences is a preferenceactivity derived class that defines two preferences entries for r.xml.advanced_preferences. One is the custom preference (described later in mypreference), whose value type is an integer and the other is Checkboxpreference, whose UI is as follows:

The purpose of this example is to obtain the Mypreference value through the Advancedpreferences setting, mypreference in the r.xml.advanced_preferences definition as follows:

<com.example.android.apis.app.mypreference

android:key= "My_preference"

android:title= "@string/title_my_preference"

android:summary= "@string/summary_my_preference"

Android:defaultvalue= "100″/>

We can see that its key is defined as my_preference.

Invoke the Advancedpreferences code as follows:

Intent launchpreferencesintent     
= new Intent (). SetClass (this, advancedpreferences.class);

Make it a subactivity so we know when it returns 
Startactivityforresult (Launchpreferencesintent,
Request_code _preferences);

Related Article

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.