Android tip 01: Use intent to jump to activity in preferencescreen

Source: Internet
Author: User

The preferencescreen in the setting can be displayed on the setting interface and the activity can be started. 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>

Com. Android. settings is the package name of the project, and COM. Android. settings. Wifi. wifisettings is the class to be started. In addition, xmlns: settings is not acceptable (what is its function ?).
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 = getcontext (); context. startactivity (mintent );}}

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.