//Serializeable传递对象的方法
public void SerializeMethod(){
Person mPerson = new Person();
mPerson.setName("frankie");
mPerson.setAge(25);
Intent mIntent = new Intent(this,IntentDemo1.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,IntentDemo2.class);
Bundle mBundle = new Bundle();
mBundle.putParcelable(PAR_KEY, mBook);
mIntent.putExtras(mBundle);
startActivity(mIntent);
}
接受:
Person mPerson = (Person)getIntent().getSerializableExtra(ObjectTranDemo.SER_KEY);
Book mBook = (Book)getIntent().getParcelableExtra(ObjectTranDemo.PAR_KEY);
//传图片
[java] view plain copy
Intent intent
= new Intent(ChangePortraitActivity.this , UserProfileActivity.class);
mImageView.setDrawingCacheEnabled(Boolean.TRUE);
intent.putExtra("BITMAP", mImageView.getDrawingCache()); //这里可以放一个bitmap
startActivity(intent);
接收图片:
[java] view plain copy
//接收的activity
Intent intent = getIntent();
if (intent
!= null &&
intent.getParcelableExtra("BITMAP") != null) {
Bitmap bitmap = (Bitmap)getIntent().getParcelableExtra("BITMAP");
mImageViewPortrait.setImageBitmap(bitmap);
}