18

I created a simple activity that I want to start from command line and pass in some value from command line.

However, if I try to do

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

and then receive the message in activity, intent.getExtras() returns null.

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");
}

Result:

SimpleActivity(12345): Intent is not null
SimpleActivity(12345): Bundle is null
Mike Lee
  • 1,215
  • 3
  • 10
  • 22
  • http://stackoverflow.com/questions/3228245/how-can-i-deliver-parameters-to-a-test-function-that-launched-using-adb-shell-a/3229077#3229077 – shiro Nov 14 '15 at 02:22

1 Answers1

30

The right command should be

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

with -n....

Mike Lee
  • 1,215
  • 3
  • 10
  • 22