android_intent传复杂类型:对象,图片

   //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);  
}  

android_intent传复杂类型:对象,图片
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值