笔记,自己用:
1、同类中
Bundle bundle=new Bundle();
bundle.putString("k2",k2);
bundle.putString("k2pos",k2pos);
bundle.putString("d2",d2);
bundle.putStringArrayList("extras",extras);
bundle.putStringArrayList("colors",colors);
Message msg=new Message();
msg.what=SQUARE_COLOR;
msg.obj=bundle;
mHandler.sendMessage(msg);
case SQUARE_COLOR:
bundle= (Bundle) msg.obj;
String k2=bundle.getString("k2");
String k2pos=bundle.getString("k2pos");
String d2=bundle.getString("d2");
ArrayList<String> extras=bundle.getStringArrayList("extras");
ArrayList<String> colors=bundle.getStringArrayList("colors");
break;
2、intent中
复杂对象:
public class DeviceInfo implements Serializable {
String Name;
String Type;
String Serial;
String Version;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getType() {
return Type;
}
public void setType(String type) {
Type = type;
}
public String getSerial() {
return Serial;
}
public void setSerial(String serial) {
Serial = serial;
}
public String getVersion() {
return Version;
}
public void setVersion(String version) {
Version = version;
}
}
在activity中使用:
case R.id.living_layout_baseinfo:
DeviceInfo deviceInfomy=new DeviceInfo();
deviceInfomy.setName(deviceInfo.getDeviceName());
deviceInfomy.setSerial(deviceInfo.getDeviceSerial());
deviceInfomy.setType(deviceInfo.getDeviceType());
deviceInfomy.setVersion(deviceInfo.getDeviceVersion());
Bundle bundle=new Bundle();
bundle.putSerializable("deviceinfo",deviceInfomy);
Intent intent_baseinfo=new Intent(this,BaseInfoActivity.class);
intent_baseinfo.putExtras(bundle);
startActivity(intent_baseinfo);
break;
在另一个activity中接收对象
private void initIntentData() {
Bundle bundle=getIntent().getExtras();
DeviceInfo info= (DeviceInfo) bundle.getSerializable("deviceinfo");
}