Introduction and analysis of Preferencescreen usage methods in Android settings

Source: Internet
Author: User

Today, we mainly study the Preferencescreen application in the setup, it can not only display as the setting interface, but also start the activity, the following is mainly the introduction of the start activity
1. Start activity in Preferencescreen
For example, the following fragments are found in Wireless_setting.xml

<preferencescreen xmlns:android= "Http://schemas.android.com/apk/res/android"
xmlns:settings= "Http://schemas.android.com/apk/res/com.seedshope.android" >
<preferencescreen
android:key= "Wifi_settings"
android:title= "@string/wifi_settings"
android:summary= "@string/wifi_settings_summary" >
<intent
android:action= "Android.intent.action.MAIN"
Android:targetpackage= "Com.android.settings"
android:targetclass= "Com.android.settings.wifi.WifiSettings"/>
</PreferenceScreen>
</PreferenceScreen>

Com.android.settings is the package name for project, and Com.android.settings.wifi.WifiSettings is the class to start.
Under normal circumstances, this will be OK, click on the corresponding preference to start the corresponding activity, but this sometimes, not necessarily can start the corresponding activity, because it is related to the callback function Onpreferencetreeclick, Sometimes we will rewrite this method such as:
public boolean Onpreferencetreeclick (Preferencescreen preferencescreen, Preference Preference) {
if ((preference = = Mairplanemodepreference) &&
(Boolean.parseboolean (
Systemproperties.get (Telephonyproperties.property_inecm_mode))) {
In ECM Mode launch ECM App Dialog
Startactivityforresult (
New Intent (telephonyintents.action_show_notice_ecm_block_others, NULL),
REQUEST_CODE_EXIT_ECM);
return true;
}
else {
Let the intents is launched by the Preference Manager
return false;
}
}
In Wirelesssetting.java, as in the function, when the return value is True, you can click on the preference will not jump to the activity, just wait until its return value is false, talent enough to jump normally, Because clicking on one of the preference's true real-preference.java performclick functions, for example, is as follows:
void PerformClick (Preferencescreen preferencescreen) {

if (!isenabled ()) {
Return
}

OnClick ();

if (Monclicklistener! = null && Monclicklistener.onpreferenceclick (this)) {
Return
}

Preferencemanager Preferencemanager = Getpreferencemanager ();
if (Preferencemanager! = null) {
Preferencemanager.onpreferencetreeclicklistener listener = Preferencemanager
. Getonpreferencetreeclicklistener ();
if (Preferencescreen! = NULL && listener! = NULL
&& Listener.onpreferencetreeclick (Preferencescreen, this)) {
Return
}
}

if (mintent! = null) {
Context context = GetContext ();
Context.startactivity (mintent);
}
}
When you click on a Preference the call flow is adapterview.performitemclick--"preferencescreen.onitemclick--" preference.performclick--" Preferenceactivity.onpreferencetreeclick, when Onpreferencetreeclick returns True, return directly, not the following to start the activity of the place, so to make a preference can Normal jump to another activity has two conditions, one is whether the XML is set correctly, and the second is whether the Java class calling the XML is onpreferencetreeclick this function needs to return FALSE.

Introduction and analysis of Preferencescreen usage methods in Android settings

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.