Monday, July 16, 2018

Chapter 3: Instant Run in Android Studio

Section 3.1: Enabling or disabling Instant Run

1. Open the Settings or Preferences dialog:

  • On Windows or Linux, select File > Settings from the main menu.
  • On Mac OSX, select Android Studio > Preferences from the main menu.

2. Navigate to Build, Execution, Deployment > Compiler.
3. In the text field next to Command-line Options, enter your command-line options.
4. Click OK to save and exit.


The top option is Instant run. Check/uncheck that box.


Section 3.2: Types of code Swaps in Instant Run

There are three types of code swaps that Instant run enables to support faster debugging and running app from your code in Android Studio.

  • Hot Swap
  • Warm Swap
  • Cold Swap

When are each of these swaps triggered?
  • HOT SWAP is triggered when an existing method's implementation is changed.
  • WARM SWAP is triggered when an existing resource is changed or removed (anything in the res folder)
  • COLD SWAP whenever there is a structural code change in your app's code e.g.
1. Add, remove, or change:
  • an annotation
  • an instance field
  • a static field
  • a static method signature
  • an instance method signature
2. Change which parent class the current class inherits from
3. Change the list of implemented interfaces
4. Change a class's static initializer
5. Reorder layout elements that use dynamic resource IDs
What happens when a code swap happens?
  • HOT SWAP changes are visible instantly - as soon as the next call to the method whose implementation is changed is made.
  • WARM SWAP restarts the current activity
  • COLD SWAP restarts the entire app (without reinstall)



Section 3.3: Unsupported code changes when using Instant Run

There are a few changes where instant won't do its trick and a full build and reinstall fo your app will happen just like it used to happen before Instant Run was born.

1. Change the app manifest
2. Change resources referenced by the app manifest
3. Change an Android widget UI element (requires a Clean and Rerun)