从命令行开始 Android activity

Start Android activity from command line with extra

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

但是,如果我尝试这样做

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

然后在activity收到消息,intent.getExtras()returnsnull.

Activity:

@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

正确的命令应该是

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

-n...