When developing an app with a big file size the time between pressing Ctrl+F5 and having the new app instance running on a connected device can be rather long.
A timespan of around 10 seconds for a 25MB app is long enough for me to deal with other things, e.g. staging my changes in the VCS and then looking back at the device wondering whether the new version is already running or if I’m looking at the old state. Usually I then start clicking to test the new implementation when the app just closes and reopens since the upload took longer than expected.
The solution is: Add a script to AndroidStudio’s build process which closes the app immediately after pressing Ctrl+F5. This way, when you see your app screen the next time, you can be sure that you are looking at the new version.
- Open Android Studio → Run → Edit Configurations
- Select your application, scroll to the bottom to the “Before launch” section. Click Plus -> Run External Tool -> Click Plus.Set the values:
Name: Force-stop app
program: adb.exe
parameters: shell am force-stop - Make sure that the external tool runs before the Gradle-aware Make in the “Before Launch” section
P.S.: An alternative would be to auto-increment the version code with every change but that is not feasible for me since I increment my version code automatically based on my git history (more on that later).