Preferencescreen usage in Android settings

Source: Internet
Author: User

Today, I mainly studied the preferencescreen application in the settings. It can be used not only as a display interface, but also as a startup activity. The following describes how to start the activity.
1. Start activity in preferencescreen
For example, wireless_setting.xml contains the following fragments:

<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 of the project, and COM. Android. settings. Wifi. wifisettings is the class to be started.
In general, it is okay to click the corresponding preference to start the corresponding activity. However, in this case, sometimes the corresponding activity may not be started, because it is related to the callback function onpreferencetreeclick, sometimes we will rewrite this method as follows:
Public Boolean onpreferencetreeclick (preferencescreen, 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 be launched by the preference Manager
Return false;
}
}
Wirelesssetting. java has the above function. If the returned value is true, you will not jump to the activity when you click preference. You can jump to the activity normally only when the returned value is false, because the actual implementation of clicking a preference is in preference. java's javasmclick function is as follows:
Void complete mclick (preferencescreen ){

If (! Isenabled ()){
Return;
}

Onclick ();

If (monclicklistener! = NULL & monclicklistener. onpreferenceclick (this )){
Return;
}

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 a preference, the calling process is adapterview. extends mitemclick -- "preferencescreen. onitemclick -- "preference. extends mclick -- "preferenceactivity. onpreferencetreeclick: When onpreferencetreeclick returns true, it returns directly and does not go through the following to start the activity. Therefore, there are two conditions for a preference to jump to another activity, the first is whether the settings in the XML are correct, and the second is whether the Java class that calls the XML is in the onpreferencetreeclick function. False must be returned.

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.