Reputation: 14585
Hi I need a little help with understanding how to send image uri
via intent.putExtra()
so I can change the source of another activity with intent.getExtra()
.
So basically I'm trying to send from Activity1 intent.putExtra("R.drawable.image");
to Activity2 and show the image.
I'm trying to do it like this :
Activity1:
intent.putExtra("image_url","R.drawable.image");
Activity2:
ImageView image = (ImageView) findViewById(R.id.image);
String image_link = getIntent().getStringExtra("image_url");
and I don't know how to set it as background to image. Any suggestions?
Upvotes: 0
Views: 10734
Reputation: 1
int[] flag_image={R.drawable.bd,R.drawable.nepal,R.drawable.india};
Intent intent = new Intent(MainActivity.this, ImageGallary.class);
intent.putExtra("image",flag_image[1]); //flag_image array index position 1 pass by nepal image send
startActivity(intent);
//ImageGallary Empty activity
imageView= (ImageView) findViewById(R.id.img);
int image_link =getIntent().getIntExtra("image",0); //0 is default value
imageView.setImageResource(image_link);
Upvotes: 0
Reputation: 4638
Frist Java Class:
i.putExtra("image_url",R.drawable.mumbai_activity);
Second Java Class:
Intent i = getIntent();
int image_link = i.getIntExtra("image_url","Default Image");
imgvw.setImageResource(image_link);
Upvotes: 0
Reputation: 10363
Activity1:
intent.putExtra("image_url",R.drawable.image);
Activity2:
ImageView image = (ImageView) findViewById(R.id.image);
int image_link = getIntent().getIntExtra("image_url", R.drawable.default);
Now you have the resource id as an int and you can use it:
imageView.setImageResource(image_link);
Upvotes: 6
Reputation: 9
wrong answer you have given buddy!!!! error at int image_link = getIntent().getIntExtra("image_url"); we have to given atleast two parameters in getIntExtra("image_url",defaultvalue);
Upvotes: 0