課程
/移動開發
/Android
/Android-深入Activity
Bitmp是使用putParcalable方式傳過去的.
2015-05-09
源自:Android-深入Activity 1-1
正在回答
沒錯,bitmap是Parcelable的實現類。圖片過大就會有:android.os.TransactionTooLargeException
建議可以把圖片url路徑或id傳過去。
發送:
? ? ? ? Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
? ? ? ? Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
? ? ? ? Bundle bundle = new Bundle();
? ? ? ? bundle.putParcelable("bitmap", bitmap);
? ? ? ? intent.putExtras(bundle);
? ? ? ? startActivity(intent);
接收:
? ? ? ? iv_content = (ImageView) findViewById(R.id.iv_content);
? ? ? ? Intent intent = getIntent();
? ? ? ? if(intent!=null){
? ? ? ? ? ? Bitmap bitmap = intent.getParcelableExtra("bitmap");
? ? ? ? ? ? iv_content.setImageBitmap(bitmap);
? ? ? ? }
舉報
帶大家深入了解Activity,講解Activity的相關知識
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2015-12-18
沒錯,bitmap是Parcelable的實現類。圖片過大就會有:android.os.TransactionTooLargeException
建議可以把圖片url路徑或id傳過去。
發送:
? ? ? ? Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
? ? ? ? Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
? ? ? ? Bundle bundle = new Bundle();
? ? ? ? bundle.putParcelable("bitmap", bitmap);
? ? ? ? intent.putExtras(bundle);
? ? ? ? startActivity(intent);
接收:
? ? ? ? iv_content = (ImageView) findViewById(R.id.iv_content);
? ? ? ? Intent intent = getIntent();
? ? ? ? if(intent!=null){
? ? ? ? ? ? Bitmap bitmap = intent.getParcelableExtra("bitmap");
? ? ? ? ? ? iv_content.setImageBitmap(bitmap);
? ? ? ? }