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.