【问题标题】:Start Android activity from command line with extra [duplicate]从命令行启动Android活动,额外[重复]
【发布时间】:2015-11-14 01:39:09
【问题描述】:

我创建了一个简单的活动,我想从命令行开始并从命令行传递一些值。

但是,如果我尝试这样做

adb shell am start com.example.mike.app/.SimpleActivity --es "Message" "hello!"

然后在activity中接收消息,intent.getExtras()返回null。

活动:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.simple_activity);

    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    Log.d(LOGTAG, intent == null ? "Intent is null" : "Intent is not null");
    Log.d(LOGTAG, bundle == null ? "Bundle is null" : "Bundle is not null");
}

结果:

SimpleActivity(12345): Intent is not null
SimpleActivity(12345): Bundle is null

【问题讨论】:

标签: android android-intent adb


【解决方案1】:

正确的命令应该是

adb shell am start -n com.example.mike.app/.SimpleActivity --es "Message" "hello!"

-n....

【讨论】:

  • 我们如何才能传递 long 类型的额外内容?
  • @UbaierBhat [--el ...]
  • docs of am start。或者,adb shell am help start 查看完整的参数列表。
猜你喜欢
  • 1970-01-01
  • 2014-01-28
  • 2021-10-15
  • 1970-01-01
  • 2013-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多