3

I have an activity that requires a parameter be passed as an intent extra when the activity is started. Is there any way I can set a demo parameter from a run configuration to allow me to to run the activity from Android Studio without creating a temporary default activity that launches the activity I am working on?

RedBassett
  • 3,469
  • 3
  • 32
  • 56
  • 1
    I think the Launch Flags will work, using [the appropriate `am` switches for extras](https://developer.android.com/studio/command-line/adb.html#am) (e.g., `-e foo bar` to set an extra named `foo` to the string value `bar`). I haven't tried this, though. – CommonsWare Feb 12 '18 at 19:40
  • This was exactly what I needed! Thanks! – RedBassett Feb 12 '18 at 22:29

1 Answers1

10

With credit to CommonsWare, here is the solution:

In the configuration, set the correct flags for am, in my case -e for a String extra:

-e "extra_key" "extra_value"

Alternatively, for an int extra, you could use the flag --ei:

--ei "extra_key" 1

This goes in the "Launch Flags" field (with a specified activity) in the launch options section of the configuration edit dialog.

RedBassett
  • 3,469
  • 3
  • 32
  • 56