Skip to content

Instantly share code, notes, and snippets.

@Zingam
Last active May 25, 2018 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zingam/13c80bf6699451dbe6af244f751c6d37 to your computer and use it in GitHub Desktop.
Save Zingam/13c80bf6699451dbe6af244f751c6d37 to your computer and use it in GitHub Desktop.

How to Pass Parameters to an Android App via Android Studio

  1. In Android Studio 3.1 open Run/Debug Configurations
  2. For the respective Configuration, e.g app under General->Launch Options->Launch Flags: add a key-value pair, e.g. --ei DAY_TIME 5. For more options see: Specification for intent arguments
  3. Read the key-value pair in Kotlin:
// Get the value with intent.extras[KEY_VALUE] which returns a value of type 
// Any!. Check for "null" and convert it to a string otherwise return a string 
// value of "24".
val dayTime = intent.extras["DAY_TIME"]?.toString() ?: "24"
val time = dayTime.toInt();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment