基本信息
源码名称:android Serializeable与Parcelable 数据对象传递例子源码下载
源码大小:0.05M
文件格式:.rar
开发语言:Java
更新时间:2015-05-20
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
package com.android.test;
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 ObjectTranActivity extends Activity implements OnClickListener
{
private Button sButton, pButton;
public final static String SER_KEY = "Serializable";
public final static String PAR_KEY = "Parcelable";
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
public void init()
{
sButton = (Button) findViewById(R.id.button1);
pButton = (Button) findViewById(R.id.button2);
sButton.setOnClickListener(this);
pButton.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
if (v.equals(sButton))
{
SerializeMethod();
}
else
{
PacelableMethod();
}
}
// Serializeable传递对象的方法
public void SerializeMethod()
{
Person mPerson = new Person();
mPerson.setName("Harvey Ren");
mPerson.setAge(26);
Intent mIntent = new Intent(this, FirstActivity.class);
Bundle mBundle = new Bundle();
mBundle.putSerializable(SER_KEY, mPerson);// 传递Person对象
mIntent.putExtras(mBundle);
startActivity(mIntent);
}
// Pacelable传递对象方法
public void PacelableMethod()
{
Book mBook = new Book();
mBook.setBookName("Android之路");
mBook.setAuthor("Harvey Ren");
mBook.setPublishDate(2012);
Intent mIntent = new Intent(this, SecondActivity.class);
Bundle mBundle = new Bundle();
mBundle.putParcelable(PAR_KEY, mBook);// 传递Book对象
mIntent.putExtras(mBundle);
startActivity(mIntent);
}
}