2015-11-14 70 views
3

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

但是,如果我尝试做

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 
+0

http://stackoverflow.com /问题/ 3228245 /何灿我-delaver-parameters-to-a-test-function-that-launching-using-adb-shell-a/3229077#3229077 – shiro

回答

4

权命令应该是

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

-n ....

+0

我们怎样才能通过额外的类型长? –

+1

@UbaierBhat [--el ...] – Sodino