意图在Android上 - 将ArrayList <drawable>传递给另一个活动</drawable>

时间:2012-07-12 03:27:25

标签: android android-intent

我有两个活动,我想传递ArrayList - &gt; drawablesFromUrl objs从活动A到活动B.部分代码如下:

在活动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);

在活动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");

执行代码后,会发生错误:

AndroidRuntime(15005): java.lang.RuntimeException: Parcel: unable to marshal value android.graphics.drawable.BitmapDrawable@4052d928

任何人都可以帮我解决问题,万分谢谢!

1 个答案:

答案 0 :(得分:0)

通过Parcelable传递您的对象。这是一个链接,它将告诉你如何相对容易地做到这一点:

http://shri.blog.kraya.co.uk/2010/04/26/android-parcel-data-to-pass-between-activities-using-parcelable-classes/