Android 通过意向向新活动传递图像url
我是android新手,目前面临一些困难。 我有一个imageview,我在其中加载了一个url,我想在用户单击图像(imageview)时通过intent将其url(image\uURL)传递给新活动。 在发送活动中(//log.d显示正确的图像\u url) 在接收活动中:Android 通过意向向新活动传递图像url,android,android-intent,Android,Android Intent,我是android新手,目前面临一些困难。 我有一个imageview,我在其中加载了一个url,我想在用户单击图像(imageview)时通过intent将其url(image\uURL)传递给新活动。 在发送活动中(//log.d显示正确的图像\u url) 在接收活动中: setContentView(R.layout.image); Intent i = getIntent(); id= i.getStringExtra(image_url); 在接收活动中,我没
setContentView(R.layout.image);
Intent i = getIntent();
id= i.getStringExtra(image_url);
在接收活动中,我没有接收通过发送活动传递的图像url。如果有人能帮忙,我将不胜感激。也许你可以试试:
Intent i = getIntent();
id = i.getExtras().getString("image_url");
通过意图传递数据的形式为putExtra(字符串名称、字符串值)
with
public Intent putExtra (String name, String value)
Parameters
name = The name of the extra data, with package prefix.
value = The String data value.
当您试图获取传递的数据时,可以使用getStringExtra(字符串名称)
where
public String getStringExtra (String name)
Parameters
name = The name of the desired item.
因此,在获取额外数据时,必须使用字符串name
——而不是变量。(对于您的情况:i.getStringExtra(“image_url”);
而不是i.getStringExtra(image_url);
)
请参阅。i.getStringExtra是否返回?您不需要调用my_image.setClickable(true);默认情况下,您的ImageView是可单击的。您在哪里为image_url变量赋值?@joao2fast4u非常感谢。Erad已将答案张贴在下面如果此解决方案对您有效,请指出它是答案并投票赞成。我已指出答案只是我不能投票赞成:(它需要15个声誉,我是新的,甚至没有一个声誉。对此表示抱歉,并感谢您的帮助
public String getStringExtra (String name)
Parameters
name = The name of the desired item.