Supercharge Android Studio’s Run Configurations
--
As developers we often find ourselves working on screens which aren’t the main/launcher activity. In such cases, it gets extremely frustrating and time-consuming to navigate to that activity through multiple clicks.
I always wondered if there is a quicker way to jump to the activity I was working on. Setting the activity as the launcher activity was one idea but then that required me to remember to remove it as the default once I was done with it. Upon further investigation, I learnt how custom Run Configurations can help.
1) Debug Variant and Exported
Let’s say you have two activities in your class, MainActivity
and SecondaryActiity
with MainActivity
being the launcher activity.
If your project is using Gradle, then it most likely has debug
and release
build types (the defaults out of the box). Create a debug
source set (generally this will go under the src
folder — the same folder that has the main
source set)
Under the debug
source set, add an AndroidManifest.xml
file. Include your SecondaryAcitivty
in this file and set android:exported="true"
. This will allow Android Studio to launch this activity directly. By putting it inside the debug variant, you make sure that it isn’t exported in your release variants, so other applications cannot launch it.
When running the debug variant, the manifest merger will make sure that the values defined in debug manifest are used.
Now create a new run configuration for your app and select the SecondaryActivity
as the activity to launch. In case you aren’t familiar with how to create a new configuration, here is a GIF:
Now make sure this new configuration is selected whenever you want to launch straight into the activity. This sadly doesn’t support intent parameters, so if you want to pass some information over, you are out of luck.
2) Deeplink
If your app supports deep links, then you can create a run configuration which takes in a URL. This will trigger the regular deep link flow, similar to a URL being clicked, and will allow you to perform your setup steps (if any).
To create a run configuration which uses deep links, select URL
and then key in your deep link URL.
Hopefully, this small tweak helps remove the annoyance of having to perform multiple steps to get to the screen you are working on. If you found the tips helpful, please applause the article. For more such tips, follow me on twitter at saurabh_arora90