我创建了一个简单的活动,我想从命令行启动并从命令行传递一些值。
但是,如果我尝试这样做
adb shell am start com.example.mike.app/.SimpleActivity --es "Message" "hello!"
然后在activity中接收消息,intent.getExtras()
返回空值。
活动:
@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");
}
Result:
SimpleActivity(12345): Intent is not null
SimpleActivity(12345): Bundle is null
正确的命令应该是
adb shell am start -n com.example.mike.app/.SimpleActivity --es "Message" "hello!"
with -n
....
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)