Reputation: 33
I am new to android and currently facing some difficulties. I have an imageview in which I have loaded a url, I want to pass its url (image_url) via intent to the new activity when the user clicks on the image(imageview). in sending activity (//log.d shows the correct image_url)
ImageView my_image = (ImageView) findViewById(R.id.single_image);
my_image.setClickable(true);
my_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), SingleImage.class);
i.putExtra("image_url", image_url);
startActivity(i);
}
});
In the receiving activity:
setContentView(R.layout.image);
Intent i = getIntent();
id= i.getStringExtra(image_url);
in the receiving activity I am not receiving the image url that I passed through the sending activity. I would really appreciated it if someone can help
Upvotes: 2
Views: 2048
Reputation: 1786
Maybe you can try:
Intent i = getIntent();
id = i.getExtras().getString("image_url");
Passing data through intents is in the form putExtra (String name, String value)
with
public Intent putExtra (String name, String value)
Parameters
name = The name of the extra data, with package prefix.
value = The String data value.
When you try to get the passed data, you can use getStringExtra (String name)
where
public String getStringExtra (String name)
Parameters
name = The name of the desired item.
So when you getExtras, you have to use the String name
- not a variable. (For your case: i.getStringExtra("image_url");
instead of i.getStringExtra(image_url);
)
Upvotes: 1