頁:
[1]
android Intent與Bundle打包資料的差異
請問一下各位大大android打包資料到另外一個畫面activity
其中使用Intent進行打包,如
Intent i = new Intent();
i.putExtra("tv", textView.getText());
startActivity(i);
跟使用Bundle進行打包,如
Bundle b = new Bundle();
b.putString("tv", textView.getText().toString);
intent.putExtras(b);
startActivity(i);
請問上述這兩種打包的差異在哪,Intent已經可以攜帶資料了,為何還需要用Bundle呢?
煩請協助解決疑惑,感謝
<div></div> Intent用來傳輸資料;
Bundle只是預先打包一筆資料, 仍是要用Intent傳輸;
用putExtra可以想成是Intent內部幫你打包成Bundle.
看看Intent的輸出, getExtras, 只有這一個, 且return Bundle, 沒有拆開的輸出;
但是他可以接收, 拆開的輸入.
可以視為, 僅是Intent提供了多種輸入方式, 依照使用場合選擇方便的來套用即可.
臨時查的資料, 如有訛誤, 請各位大大指教.
頁:
[1]