package com.zjl.passObject.activity;
import java.io.Serializable;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.zjl.passObject.Bean.PassObject_Parcelable;
import com.zjl.passObject.Bean.PassObject_Serializable;
/**
* 传递对象的页面A
* @author Administrator
*
*/
public class ActivityA extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page_a);
Button btnSerlizableBtn = (Button)ActivityA.this.findViewById(R.id.go_btn1);
Button btnParcelableBtn = (Button)ActivityA.this.findViewById(R.id.go_btn2);
btnSerlizableBtn.setOnClickListener(new mybtnClick(true, new PassObject_Serializable(1,"牛奶", 50.0)));
btnParcelableBtn.setOnClickListener(new mybtnClick(false, new PassObject_Parcelable(1,"牛奶", 50.0)));
}
/**
* 单击类
*/
private class mybtnClick implements OnClickListener {
private boolean type = false; //true 为 Serializable false 为Parcelable
private Object passObj =null; //要传递的对象
public mybtnClick(boolean type, Object passObj) {
super();
this.type = type;
this.passObj = passObj;
} @Override
public void onClick(View v) {
Bundle mybundle = new Bundle();
mybundle.putBoolean("type",type);
if(type){
mybundle.putSerializable("obj",(Serializable) passObj );
}else{
mybundle.putParcelable("obj",(Parcelable) passObj);
}
Intent myintent = new Intent();
myintent.putExtras(mybundle);
myintent.setClass(ActivityA.this, ActivityB.class);
startActivity(myintent);
}
}
}
- 1
- 2
前往页