Android中使用Intent传递对象
Intent 也可以传递对象的,例子如下:
MyParcelable.java 文件:
Java代码
package com.ldq.parcelable;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MyParcelable extends Activity {
private Button button;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Student student = new Student();
student._id = 1001;
student.name = "zhang";
student.sex = 1;
student.age = 10;
Intent intent = new Intent(MyParcelable.this,
AnotherActivity.class);
intent.putExtra("student", student);
startActivity(intent);
}
});
}
}
Student.java 文件:
Java代码
相关新闻>>
- 发表评论
-
- 最新评论 更多>>