[英]Running an Android activity with an intent
I have an activity that requires a parameter be passed as an intent extra when the activity is started. 我有一个活动,该活动需要在启动活动时作为额外的意图传递参数。 Is there any way I can set a demo parameter from a run configuration to allow me to to run the activity from Android Studio without creating a temporary default activity that launches the activity I am working on?
有什么方法可以从运行配置中设置演示参数,以允许我从Android Studio运行活动,而无需创建启动我正在处理的活动的临时默认活动?
With credit to CommonsWare , here is the solution: 归功于CommonsWare ,这里是解决方案:
In the configuration, set the correct flags for am
, in my case -e
for a String
extra: 在配置中,为
am
设置正确的标志 ,在我的情况下-e
为String
额外设置:
-e "extra_key" "extra_value"
Alternatively, for an int
extra, you could use the flag --ei
: 另外,对于
int
附加项,可以使用标志--ei
:
--ei "extra_key" 1
This goes in the "Launch Flags" field (with a specified activity) in the launch options section of the configuration edit dialog. 它位于配置编辑对话框的启动选项部分的“启动标志”字段(具有指定的活动)中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.