Android Types of code Swaps in Instant Run


Example

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
  1. Change which parent class the current class inherits from
  2. Change the list of implemented interfaces
  3. Change a class's static initializer
  4. 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)