這個問題可能聽起來很愚蠢,但我知道什麼時候我們將活動名稱放在Intent.putExtra()
?在其中一種情況下,我們只在bundle中添加額外的內容,而在其他情況下,我們將它與類名一起傳遞。我有點困惑,如果我們使用Intent.putExtra(String, Bundle)
我們已經通過Intent
構造函數的活動名稱或不?Intent.putExtra(String,Bundle)vs Intent.putExtra(Bundle)
感謝您的幫助!
這個問題可能聽起來很愚蠢,但我知道什麼時候我們將活動名稱放在Intent.putExtra()
?在其中一種情況下,我們只在bundle中添加額外的內容,而在其他情況下,我們將它與類名一起傳遞。我有點困惑,如果我們使用Intent.putExtra(String, Bundle)
我們已經通過Intent
構造函數的活動名稱或不?Intent.putExtra(String,Bundle)vs Intent.putExtra(Bundle)
感謝您的幫助!
我想你的意思putExtra(String, Bundle)
VS putExtras(Bundle)
(與小號)。
第一個將捆綁添加爲您提供的密鑰的值。該包簡單的是一個對象值。
第二個將所提供的包中的所有鍵/值對添加到意圖。在這種情況下,包的內容將被添加到意圖中,而不是包本身。他們的
想象的那樣在Map
接口:
Map.put(String key, Object value)
VS
Map.putAll(Map anotherMap)
的辦法就是這裏的區別。如果您使用的是Bundle
你可以存儲幾乎所有類型的變量:
Bundle mBundle = new Bundle();
mBundle.put(key, value);
,並把它傳遞給活動
mIntent.putExtras(mBundle);
,並在臨危的信息的其他活動,只要抓住的內容束這樣的:
Bundle extras = getIntent().getExtras();
並在bundle
這樣抓住每個元素:
extras.getString("myKey")
Bundle用於分配一些空間,而我們使用put extra和get extra通過bundle(分配的空間)只有它會傳輸 – Ramkumar 2012-08-10 11:01:14