android串行化getSerializable、getSerializableExtra 传参 总结
案例1 不用 Bundle 封装数据
提交activity
lst.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view,
int position, long id) { HashMap map=(HashMap) parent.getItemAtPosition(position);
Intent intent=new Intent();
intent.setClass(btsAllinfoActivity.this,btsMapActivity.class);
intent.putExtra("bts_map", map);
startActivity(intent); }
});
接收数据activity
Intent intent=getIntent();
map=(HashMap)intent.getSerializableExtra("bts_map");
System.out.println("");
System.out.println(map.get("bt_id"));
System.out.println(map.get("bt_name"));
System.out.println(map.get("bt_lon"));
System.out.println(map.get("bt_lat"));
System.out.println("");
案例二 用Bundle封装数据
提交activity
HashMap map=(HashMap) parent.getItemAtPosition(position);
Intent intent=new Intent();
intent.setClass(btsAllinfoActivity.this,btsMapActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("bts_map", map);
intent.putExtras(bundle); startActivity(intent);
接收activity
Bundle bundle = getIntent().getExtras(); map=(HashMap)bundle.getSerializable("bts_map"); System.out.println("");
System.out.println(map.get("bt_id"));
System.out.println(map.get("bt_name"));
System.out.println(map.get("bt_lon"));
System.out.println(map.get("bt_lat"));
System.out.println("");