使用额外的命令行启动Android活动
我创建了一个简单的活动,我想从命令行开始,并从命令行传入一些值 然而,如果我尝试这样做使用额外的命令行启动Android活动,android,android-intent,adb,Android,Android Intent,Adb,我创建了一个简单的活动,我想从命令行开始,并从命令行传入一些值 然而,如果我尝试这样做 adb shell am start com.example.mike.app/.SimpleActivity --es "Message" "hello!" 然后在活动中接收消息,intent.getExtras()返回null 活动: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedI
adb shell am start com.example.mike.app/.SimpleActivity --es "Message" "hello!"
然后在活动中接收消息,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
正确的命令应该是
adb shell am start -n com.example.mike.app/.SimpleActivity --es "Message" "hello!"
有了
-n
…我们如何才能传递额外的long类型?@UbaierBhat[--el…]就有了。或者,adb shell am help start
查看完整的参数列表。