(轉)android技巧01:Preferencescreen中利用intent跳轉activity

原文連接:http://blog.csdn.net/xianming01/article/details/7543464

?

設置中的Preferencescreen不僅可以作為設置界面顯示,而且還能夠啟動activity,下面主要是對啟動activity的介紹
1. Preferencescreen中啟動activity

例如wireless_setting.xml中有如下片段

?

[html]?view plaincopy
  1. <PreferenceScreen?xmlns:android="http://schemas.android.com/apk/res/android"??
  2. xmlns:settings="http://schemas.android.com/apk/res/com.seedshope.android">??
  3. ????<PreferenceScreen??
  4. ????????android:key="wifi_settings"??
  5. ????????android:title="@string/wifi_settings"??
  6. ????????android:summary="@string/wifi_settings_summary"?>??
  7. ????????<intent??
  8. ????????????android:action="android.intent.action.MAIN"??
  9. ????????????android:targetPackage="com.android.settings"??
  10. ????????????android:targetClass="com.android.settings.wifi.WifiSettings"?/>??
  11. ????</PreferenceScreen>??
  12. </PreferenceScreen>??

? ? ? ? 其中com.android.settings是工程的包名,com.android.settings.wifi.WifiSettings是要啟動的類。另外,xmlns:settings這一項沒有也是可以的(那它的作用是什么?)。
? ? ? ? 一般情況下,這樣就ok了,點擊對應的Preference就能夠啟動對應的activity,然而僅僅這樣有時這樣,并不一定能夠啟動對應的activity,因為它與回調函數onPreferenceTreeClick有關,有時候我們會重寫這個方法如:

?

?

[java]?view plaincopy
  1. public?boolean?onPreferenceTreeClick(PreferenceScreen?preferenceScreen,?Preference?preference)?{??
  2. ???????if?(?(preference?==?mAirplaneModePreference)?&&??
  3. ????????????????(Boolean.parseBoolean(??
  4. ????????????????????SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE)))?)?{??
  5. ????????????//?In?ECM?mode?launch?ECM?app?dialog??
  6. ???????????startActivityForResult(??
  7. ????????????????new?Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS,?null),??
  8. ????????????????REQUEST_CODE_EXIT_ECM);??
  9. ????????????return?true;??
  10. ????????}??
  11. ????????else?{??
  12. ????????????//?Let?the?intents?be?launched?by?the?Preference?manager??
  13. ????????????return?false;??
  14. ???????}??
  15. ????}??

? ? ? ??其中WirelessSetting.java中有如上函數,當返回值為true時,你怎么點擊Preference都不會跳轉到activity的,只有等到它的返回值為false的時候,才可以正常跳轉,因為點擊某一個Preference的真正實現在Preference.java的performClick函數中如下:

?

?

[java]?view plaincopy
    1. void?performClick(PreferenceScreen?preferenceScreen)?{??
    2. ??????????
    3. ????????if?(!isEnabled())?{??
    4. ????????????return;??
    5. ????????}??
    6. ??????????
    7. ????????onClick();??
    8. ??????????
    9. ????????if?(mOnClickListener?!=?null?&&?mOnClickListener.onPreferenceClick(this))?{??
    10. ????????????return;??
    11. ????????}??
    12. ??????????
    13. ????????PreferenceManager?preferenceManager?=?getPreferenceManager();??
    14. ????????if?(preferenceManager?!=?null)?{??
    15. ????????????PreferenceManager.OnPreferenceTreeClickListener?listener?=?preferenceManager??
    16. ????????????????????.getOnPreferenceTreeClickListener();??
    17. ????????????if?(preferenceScreen?!=?null?&&?listener?!=?null??
    18. ????????????????????&&?listener.onPreferenceTreeClick(preferenceScreen,?this))?{??
    19. ????????????????return;??
    20. ????????????}??
    21. ????????}??
    22. ??????????
    23. ????????if?(mIntent?!=?null)?{??
    24. ????????????Context?context?=?getContext();??
    25. ????????????context.startActivity(mIntent);??
    26. ????????}??
    27. ????} ?

轉載于:https://www.cnblogs.com/lovers/articles/2679856.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/274612.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274612.shtml
英文地址,請注明出處:http://en.pswp.cn/news/274612.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Vue 2.7 正式發布,代號為 Naruto

大家好&#xff0c;我是若川。持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。…

js設置css色相旋轉_色相旋轉顏色方案是否保留了對色盲友好的能力?

js設置css色相旋轉Hue rotation is often an easy way to change the appearance of a plot or figure without the need to create a new colour bar. However, when dealing with colourblindness, it is important to ensure that the spacing between colours is sufficien…

Tyvj 1921 Freda的煩惱

我就不說是CF hot days 原題了&#xff0c;我會告訴你使用Math庫是因為一開始偷懶不想寫Min函數么- 1 Uses math;2 Var n,m,i,t,tt,x,cost,ans,tmp:qword;3 Function min(x,y:qword):qword;4 Begin5 if x>y then exit(y);6 exit(x);7 end;8 Begin9 readln(n,m);10 …

ux設計中的各種地圖_在UX設計中使用阿拉伯語

ux設計中的各種地圖Last year I got to work on an app that was ultimately going to be deployed globally in every market and every language including RTL (Right-to-Left) languages — with a specific focus on Arabic.去年&#xff0c;我開始致力于開發一個應用程序…

如何為前端項目一鍵自動添加eslint和prettier的支持

本文來自讀者那個曾經的少年回來了 寫的源碼共讀35期筆記文章&#xff0c;授權投稿&#xff0c;寫的真好。本文參加了由公眾號若川視野 發起的每周源碼共讀活動&#xff0c;點此加我微信 ruochuan12 了解詳情一起參與。本文屬于源碼共讀第35期 | 為 vite 項目自動添加 eslint 和…

Server.Transfer方法在頁面間傳值

a.aspx頁面代碼&#xff1a; protected void Button5_Click(object sender, EventArgs e){Server.Transfer("b.aspx");}public string name{get{return this.TextBox1.Text;}} b.aspx頁面代碼&#xff1a; private void TheFour(){a newWebContext.Handler as a;//創…

極端原理_為極端而設計

極端原理*You can also read this article in German here.*您也可以 在此處 閱讀 德語文章 。 In this article I’m going to draw on the Design thinking concept of designing for extreme users and I will argue that designing for extreme users can be considered a…

當CV工程師碰到了拷貝粘貼的需求——useClipboard的使用及源碼解析

大家好&#xff0c;我是若川。持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。…

centos利用tar包安裝phpmyadmin

我的網站根目錄地址為/var/www/html&#xff0c;phpmyadmin安裝包在/tmp下。 注意&#xff1a;php版本低于5.1的建議安裝phpmyadmin2.11&#xff0c;因為phpmyadmin3.3對php版本的最低要求是php5.2 1 [rootCentOS ~]# tar -zxvf /tmp/phpMyAdmin-2.11.9-all-languages.tar.gz …

ux和ui_從UI切換到UX設計

ux和uiI still remember those days, when I was a soon-to-be graphic design graduate who started to question what my future will be. At that time, I realized that I loved graphic design, but I wasn’t sure if I enjoyed doing it. Creating logos, posters, broc…

春季招聘后前端工程師的就業指南

盡管疫情反復&#xff0c;大廠裁員&#xff0c;招聘季仍是在困難中有條不紊地落下了尾聲。回顧今年的春季招聘&#xff0c;北京青年報記者發現&#xff0c;互聯網“大廠”依然對“研發崗”需求最為旺盛。但許多企業最近都在圍繞“降本提效”來進行業務調整&#xff0c;這對技術…

探索式測試的思維模型

上一章介紹了探索式測試的定義。在實際項目的測試執行過程中&#xff0c;讀者是否曾遇到如下的幾個現象&#xff1a; 測試人員按照一個測試用例來執行測試&#xff0c;得到的程序輸出與預期輸出不一致。 測試人員判斷程序的行為并不是缺陷&#xff0c;但根據新的輸出想到了新的…

圖解Git分支和命令

大家好&#xff0c;我是若川。持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。…

vsco_VSCO重新設計:更直觀,更簡化的界面

vscoAmong the many photo-editing apps, VSCO has definitely become a popular favorite among both experienced photographers as well as “aesthetic” Instagram users. However, my interaction with the app starts and ends with using a few key filters and (maybe…

不同長度數據項的排序

注&#xff1a;本文改編自windmissing博客&#xff0c;感謝作者整理&#xff01; 題目&#xff1a; a)給定一個整數數組&#xff0c;其中不同的整數中包含的數字個數可能不同&#xff0c;但是該數組中&#xff0c;所有整數中總的數字數為n。說明如何在O(n)時間內對該數組進行排…

淺談前端埋點監控

大家好&#xff0c;我是若川。持續組織了近一年的源碼共讀活動&#xff0c;感興趣的可以 加我微信lxchuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。同時極力推薦訂閱我寫的《學習源碼整體架構系列》 包含20余篇源碼文章。歷史面試系列。另外&…

css版式_第2部分:使版式具有響應能力,并為以后的版本奠定基礎

css版式The feedback I’ve received over the past week has been amazing, and matches my own excitement about this project. I’ve spent a lot of time researching, writing, and teaching about creating better typography for reading on digital devices over the …

BBS項目--登錄

BBS階段性測試總要求 django登錄報錯 Error: [WinError 10013] 以一種訪問權限不允許的方式做了一個訪問套接字的嘗試。 原因分析&#xff1a;出現這種情況在Windows中很常見&#xff0c;就是端口被占用 解決措施&#xff1a;這時我們只需改一下端口便可以了 登錄前端頁面(HTML…

【聲明】

我的公眾號和朋友圈有時會有一些課程推廣廣告&#xff0c;微博的收入來源。我接的廣告一般來說都是比自己去買會優惠不少&#xff0c;我也會想方設法爭取到更多福利&#xff08;優惠&#xff09;。買過的都知道確實優惠。如果有人看到覺得不合適&#xff0c;不想看到&#xff0…

Win7 訪問共享時輸入正確密碼仍然提示密碼錯誤

1、直接按下winr鍵&#xff0c;輸入secpol.msc&#xff0c;打開本地安全策略。 2、找到“安全設置”的“本地策略”的“安全選項” 3、在右邊一欄找到“網絡安全&#xff1a;LAN管理器身份驗證級別”&#xff0c;雙擊進入 4、在默認狀態選項下&#xff0c;英文版應該為"no…