开发者

passing arraylist of bitmap from activity to another

I have an android where i want to pass a arraylist of bitmap from one activity to andother .how can i do that.

ArrayList<String> questionArray;

 ArrayList<Bitmap>questionBitmap=new ArrayList<Bitmap>(); questionBitmap=loadBitmapFromAllArray(questionArray);public ArrayList<Bitmap> loadBitmapFromAllArray(ArrayList<String> questionArray) 
    {
        URL questionUrl = null;
        ArrayList<Bitmap>questionBitmap=new ArrayList<Bitmap>();
         for(int b =0; b <questionArray.size(); b+=1)
   开发者_运维问答         {
                String questionSource=questionArray.get(b);
                try 
                {
                     questionUrl=new URL(questionSource);
                } 
                catch (MalformedURLException e)
                {
                    e.printStackTrace();
                }
                questionBitmap.add(getRemoteImage(questionUrl));
            }
        return questionBitmap;  
    }
     public Bitmap getRemoteImage(final URL aURL) { 
         try {
                 final URLConnection conn = aURL.openConnection();
                 conn.connect();
                 final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
                 final Bitmap bm = BitmapFactory.decodeStream(bis);
                 bis.close();
                 return bm;
         }
         catch (IOException e) 
         {
         }
         return null;
 }


        Intent myIntent = new Intent(arg1.getContext(), picViewer.class);
        Bundle bundle = new Bundle();
        bundle.putParcelableArray("images", your_array);
        myIntent.putExtras(bundle);

EDIT

this could be done because Bitmap implements Parcelable!


I guess your arraylist of bitmaps is an array of strings with the filenames of bitmaps...

Example of sending from activity A to activity B :

Intent i = new Intent (YourContext, ReceiverClass.class);
i.putExtra("bmpArray", yourBitmapArray);
context.startActivity(i);

And in the receiving activity:

receivingBitmapArray = getIntent().getStringArrayExtra("bmpArray");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜