26
2017
09

Intent数据的传递2017——09——15

9/15/2017 1:38:01 PM

数据的传递数据


第一种:


Intent intentSimple = new Intent();  

intentSimple.setClass(MainActivity.this,SimpleActivity.class);  



Bundle bundleSimple = new Bundle();  

bundleSimple.putString("usr", "xcl");  

bundleSimple.putString("pwd", "zj");  

intentSimple.putExtras(bundleSimple);  

startActivity(intentSimple); 

接收参数:

Bundle bunde = this.getIntent().getExtras();  

String eml = bunde.getString("usr");  

String pwd = bunde.getString("pwd");

第二种:


/传递复杂些的参数

Map<String, Object> map1 = new HashMap<String, Object>();  

map1.put("key1", "value1");  

map1.put("key2", "value2");  

List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();  

list.add(map1);  



Intent intent = new Intent();  

intent.setClass(MainActivity.this,ComplexActivity.class);  

Bundle bundle = new Bundle(); 

ArrayList bundlelist = new ArrayList();   

bundlelist.add(list);   

bundle.putParcelableArrayList("list",bundlelist);  

intent.putExtras(bundle);                

startActivity(intent); 

接收参数:


Bundle bundle = getIntent().getExtras();   

         ArrayList list = bundle.getParcelableArrayList("list"); 

上一篇:基于MVVM架构的BaseActivity封装 下一篇:Commom(十)—— ConfigReader