开发学院手机开发Android 开发 Android中Intent传递对象的两种方法(Serializable... 阅读

Android中Intent传递对象的两种方法(Serializable,Parcelable)

 2010-10-19 20:18:07 来源:WEB开发网   
核心提示:public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);setupViews();}//我的一贯作风呵呵public void setupViews

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

setupViews();

}

//我的一贯作风呵呵

public void setupViews(){

sButton = (Button)findViewById(R.id.button1);

pButton = (Button)findViewById(R.id.button2);

sButton.setOnClickListener(this);

pButton.setOnClickListener(this);

}

//Serializeable传递对象的方法

public void SerializeMethod(){

Person mPerson = new Person();

mPerson.setName("frankie");

mPerson.setAge(25);

Intent mIntent = new Intent(this,ObjectTranDemo1.class);

Bundle mBundle = new Bundle();

mBundle.putSerializable(SER_KEY,mPerson);

mIntent.putExtras(mBundle);

startActivity(mIntent);

}

//Pacelable传递对象方法

public void PacelableMethod(){

Book mBook = new Book();

mBook.setBookName("Android Tutor");

mBook.setAuthor("Frankie");

mBook.setPublishTime(2010);

Intent mIntent = new Intent(this,ObjectTranDemo2.class);

Bundle mBundle = new Bundle();

mBundle.putParcelable(PAR_KEY, mBook);

mIntent.putExtras(mBundle);

startActivity(mIntent);

}

//铵钮点击事件响应

public void onClick(View v) {

if(v == sButton){

SerializeMethod();

}else{

PacelableMethod();

}

}

}

package com.tutor.objecttran;

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 ObjectTranDemo extends Activity implements OnClickListener

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:Android Intent 传递

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接