Bundle類


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取出一個可序列化的對象


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM