[英]intent on Android - pass ArrayList<Drawable> to another activity
I have two activity and I want to pass ArrayList -> drawablesFromUrl objs from activity A to activity B. Parts of the code is listed as follow: 我有两个活动,我想将ArrayList-> drawablesFromUrl objs从活动A传递到活动B。部分代码如下:
In Activity A: 在活动A中:
Intent i = new Intent(getApplicationContext(),SitePhotoFullScreen.class);
Bundle myData = new Bundle();
myData.putInt("id", position);
myData.putInt("MaxId", imgAdapter.getCount());
myData.putSerializable("myObjArray",drawablesFromUrl);<---- this objs
i.putExtras(myData);
startActivity(i);
In Activity B 在活动B中
ArrayList<Drawable> myObjArray = new ArrayList<Drawable>();
// get intent data
Intent i = getIntent();
Bundle myBundle = i.getExtras();
position = myBundle.getInt("id");
MaxId = myBundle.getInt("MaxId");
myObjArray = (ArrayList<Drawable>) i.getSerializableExtra("myObjArray");
After execute the code, an error occur : 执行代码后,发生错误:
AndroidRuntime(15005): java.lang.RuntimeException: Parcel: unable to marshal value android.graphics.drawable.BitmapDrawable@4052d928
Anyone can help me to solve the problem, thousand thanks! 任何人都可以帮助我解决问题,万分感谢!
Pass your object via Parcelable
. 通过
Parcelable
传递对象。 Here is a link that will show you how to do that with relative ease: 这里的链接将向您展示如何相对轻松地做到这一点:
http://shri.blog.kraya.co.uk/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/ http://shri.blog.kraya.co.uk/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.