精華區beta AndroidDev 關於我們 聯絡資訊
※ 引述《pokk (璐琺)》之銘言: : 在傳遞Activity參數之間的程式寫法, : 我有在書上看過這樣的程式碼, : 單純用intent傳遞參數 : 另一種方式是使用Bundle的方式 兩個東西就程式碼來講,其實是一樣的。 簡單來說 Intent 裡面已經有個 Bundle 型態的變數, 第一種作法利用 Intent.putXXXExtra,就是塞到這個 Bundle 之中。 第二種作法先利用 Bundle 做了一堆事情,再塞到 Intent 裡, 利用的就是 Bundle.putAll() 節錄片段程式碼如下,前面數字代表行數: 2594 private Bundle mExtras; 4703 public Intent putExtras(Bundle extras) { 4704 if (mExtras == null) { 4705 mExtras = new Bundle(); 4706 } 4707 mExtras.putAll(extras); 4708 return this; 4709 } 2594 行宣告了一個 Bundle 型態的變數,叫做 mExtras。 4703 行,就是傳入一個 Bundle,再把這 Bundle 的內容全數塞改 mExtras。 4xxx 行一堆 putXXXExtra 的函式也是大同小異,也都是把內容丟給 mExtras。 source code 位置 /frameworks/base/core/java/android/content/Intent.java 或是參考網頁(android git) http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob; f=core/java/android/content/Intent.java;h =de8e3f450427e2bd546bab22d8269d08b50a8a6a;hb=HEAD http://tinyurl.com/633yp3r -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.119.80.94