How to transfer image data from one activity to another?

I use two actions. One action displays images in a GridView and by clicking on a specific image in that GridView , it should display a full-screen image in another action.

How can i achieve this?

My MyGridView.java

 mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position,long id) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "Image"+(position+1),Toast.LENGTH_SHORT).show(); System.out.println(id); Intent i = new Intent(this, MyImageViewActivity.class); Bundle bundle = new Bundle(); bundle.putInt("image", position); i.putExtras(bundle); startActivityForResult(i, 0); } }); 
+3
source share
9 answers

In MyGridView: (someInteger is an integer that represents the index of the selected image

 Intent myIntent = new Intent(this, MyImageViewActivity.class); Bundle bundle = new Bundle(); bundle.putInt("image", someInteger); myIntent.putExtras(bundle); startActivityForResult(myIntent, 0); 

In MyImageViewActivity:

 Bundle bundle = this.getIntent().getExtras(); int pic = bundle.getInt("image"); 

Of course, you can put something in the kit! maybe an array of bytes or something

+2
source

Pass the image url / uri instead of passing the raw image data.

+3
source

You pass the parameters to the action in the intent. If the image comes from a file, pass the String path, otherwise pass Bitmap

 startActivity(new Intent(this, YourActivity.class).putExtras(new Bundle().putParcelable("bitmap", Bitmap))) 
+2
source

Transferring data between two actions:

 bytes[] imgs = ... // your image Intent intent = new Intent(this, YourActivity.class); intent.putExtra("img", imgs); startActivity(intent); 

Then in YourActivity:

 bytes[] receiver = getIntent().getExtra("imgs"); 

Also follow this link which will also help u.
Here you can learn how to convert bitmaps to bytes.

+2
source

After clicking the Grid View element, get the click and pass it to the next activity as an argument via PutExtra . In the next step, extract the image from the additional functions and show it to the user

+1
source

I suppose you need to use the Intent class.

 Intent intent = new Intent(YourSourceActivity.this, TargetActivty.class); Bundle addinfo = new Bundle(); addinfo.putInt("imageid", someid); intent.putExtras(addinfo); 
+1
source

Try passing the id associated with the image through aim.putExtra () and get it through the bundle when the activity is running.

0
source

in Activity converts the image to ByteArray and adds it to the intent as

 intent.putExtra("img",<ByteArray>); 

then startActivity B.

In action B

 Bitmap bm = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("img"), 0, getIntent().getByteArrayExtra("img").length); 

This way you can transfer the image between actions.

0
source

This is my process: it is so good. Activity1:

 ByteArrayOutputStream stream=new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream); byte[] byteArray=stream.toByteArray(); Intent intent = new Intent(getApplicationContext(), FrameActivity.class); intent.putExtra("Image", byteArray); startActivity(intent); 

in FrameActivity.class

 collageView = (CollageView) findViewById(R.id.btn_collage); byte[] byteArray = getIntent().getByteArrayExtra("Image"); Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); collageView.setImageBitmap(bmp); 
0
source

All Articles