1.新建一個Bundle類
Bundle bundle=new Bundle();
2.Bundle類中放入數據(key-value的形式,另一個Activity里面取數據的時候,通過key值找出對應的value值)
bundle.putString("key" ," value");
3.新建一個intent對象,並將該bundle加入到這個intent對象
Intent intent=new Intent( );
intent.putExtras(bundle);
4.獲取key所對應的value
Bundle bundle=getIntent().getExtras();
String data=bundle.getString("key");
Bundle是一個簡單的數據攜帶包,該對象也包含了多個方法來存入數據:
putXxx(String key, Xxx data):向Bundle中放入Int、Long等各種類型的數據
putSerializable(String key, Serializable data):向Bundle中放入一個可序列化的對象
取出Bundle數據攜帶包里的數據的方法:
getXxx(String key):從Bundle取出Int、Long等各種類型的數據
getSerializable(String key,Serializable data):從Bundle取出一個可序列化的對象