Start Android activity from command line with extra
25,600
The right command should be
adb shell am start -n com.example.mike.app/.SimpleActivity --es "Message" "hello!"
with -n
....
Author by
Mike Lee
Updated on November 17, 2020Comments
-
Mike Lee over 3 years
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
-
Ubaier Bhat over 6 yearsHow can we pass then extra of type long?
-
Sodino over 6 years@UbaierBhat [--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]
-
Weekend about 6 yearsThere is the docs of am start. Or,
adb shell am help start
to view the full args list.