how do you pass images (bitmaps) between android activities using bundles?

后端 未结 9 1259
自闭症患者
自闭症患者 2020-11-22 09:56

Suppose I have an activity to select an image from the gallery, and retrieve it as a BitMap, just like the example: here

Now, I want to pass this BitMap to be used i

9条回答
  •  面向向阳花
    2020-11-22 10:40

    in first.java

    Intent i = new Intent(this, second.class);
                        i.putExtra("uri",uri);
                        startActivity(i);
    

    in second.java

    Bundle bd = getIntent().getExtras();
            Uri uri = bd.getParcelable("uri");
            Log.e("URI", uri.toString());
            try {
                Bitmap bitmap = Media.getBitmap(this.getContentResolver(), uri);
                imageView.setImageBitmap(bitmap);
    
            } 
            catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    

提交回复
热议问题