When the APK is present on the target device, you can start sending over small, incremental patches that will be applied. This is a huge timesaver in a multitude of ways: The build process no longer needs to package and build the code parts that have not changed — just rebuild the deltas. Less data needs to be pushed to the device over ADB. Once on the device, the dex2oat has a lot less work to do, compared to a full APK install. There are 3 types of swaps in total — hot swap, warm swap and cold swap. The initially built APK has to be modified to support these swaps.
On a high level, a client to server communication will be established between the application and Android Studio.
The data itself is transferred via ADB. This way it can work both over wireless and over USB, depending on your setup. Hot swap updates your application code without a new APK. This is done by adding stub methods that will be executed the next time the method is called. For example: if you update something in a View. It is important to remember that it is your responsibility as a developer to make sure the method does get called after the swap. Warm swap is rather similar to hot swap. Its main use case is to update resources on the fly.
Running Debug Commands from the Instant UI
As the resources are usually inflated in the starting stages of Activities and Fragments, it is useful to do an Activity. This saves us from having to manually navigate between screens or even worse — write some boilerplate code to enforce inflating of layouts. Cold swap is used to make structural changes to the application that cannot be supported by hot or warm swapping.
These changes are different for both tools and we will take a look at those in the next section. Cold swap differs from hot and warms swaps by having to restarting the application. Here is the short version, code changes are handled this way: Hot Swap — New code is executed in the next call.
Warm Swap — New code is executed after the activity restarts. Cold Swap — New code is executed after the application restarts.
Changes to resources have fewer options: Warm Swap — New resources are used after the activity restarts. Cold Swap — New resources are used after the application restarts.
Once the updated code is transferred to the device, Instant Run will perform a hot or warm swap. When enabled and it is by default , you will get a warm swap.
Existing resource changes with Instant Run will always be handled using a wam swap. This feature will work for all apps that target Ice Cream Sandwich and later.
Cuthbertson politely refused to tell us how exactly Instant Run works, but promised that Google will detail the technology behind this feature in the future. Developers will also be able to emulate different network conditions and emulate the GPS even with pre-configured paths.
The emulator also includes access to all the standard Google Play services.
Disabling Android Studio Instant Run
For developers who build graphics-intensive apps and games, the Studio now also includes a new GPU profiler. This tool is still officially in preview. One area Google has recently focused on is app indexing , which brings content from apps into its search engine. The Android Studio team worked closely with the Search team to make it easier to enable this feature in new apps.
Related Instant running
Copyright 2019 - All Right Reserved