我創建了一個簡單的活動,我想從命令行開始並從命令行傳遞一些值。從額外的命令行啓動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
http://stackoverflow.com /問題/ 3228245 /何燦我-delaver-parameters-to-a-test-function-that-launching-using-adb-shell-a/3229077#3229077 – shiro