32

Today I have updated my Android Studio and run the app which existing with previous version.When I was running the app with previous version app launching very fast but when I updated android studio and run the same app with updated version then app was taking too much time to launch.I googled for the issue and found that if instant run is enable then disable this so I have done the same and app launched as fast as it was.

Now my question is-

  1. What is instant run?What are pron and cons to use it?
  2. Why app taking too much time to launch when instant run was enabled and when i disabled it then why it launched the app fast as it was.
MMG
  • 3,226
  • 5
  • 16
  • 43
DkThakur
  • 516
  • 2
  • 5
  • 17

4 Answers4

33

Instant run comes with the latest version of Android Studio. But in some cases it is wired when using that.

What is Instant Run?

In an ordinary build and run the whole APK file is updated and pushed to the device. But when using instant run only the updated part gets replaced in the device. Instant Run pushes updated code and resources to your connected device or emulator by performing a hot swap, warm swap, or cold swap. It automatically determines the type of swap to perform based on the type of change you made.

Pros

It may be faster than an ordinary build. But it requires the application to be running at the time of build below API 21.

Cons

Seriously I felt a problem of the unchanged installation. That is when using instant run at some times the application seems to not updating. It is staying at its previous build. And sometimes I felt it was slower than an ordinary build.

Hot swap:

This is the fastest type of swap and makes changes visible much more quickly. Your application keeps running and a stub method with the new implementation is used the next time the method is called.

Warm Swap:

This swap is still very fast, but Instant Run must restart the current activity when it pushes the changed resources to your app.

Cold swap (API level 21 or higher):

This swap is a bit slower because, although a new APK file is not required, Instant Run must restart the whole app when it pushes structural code changes.

Disabling instant run: File=>Settings=>Build,Execution and deployment=>Instant Run=>Uncheck enable instant run for hot swap

Enter image description here

See this documentation.

Community
  • 1
  • 1
Kiran Benny Joseph
  • 6,755
  • 4
  • 38
  • 57
  • @DkThakur It may because of cold swap – Kiran Benny Joseph Mar 01 '17 at 05:25
  • It clears my first point but not my second point still i am looking for my second point and now i am accepting this as answer but remember,this is not the answer of my second point.If anyone have answer of my second point please leave a comment. – DkThakur Mar 01 '17 at 14:02
11

Instant Run = Incremental build + Hot, Warm, or Cold swap

Without Instant run :

enter image description here

With instant run :

enter image description here

Source : https://medium.com/google-developers/instant-run-how-does-it-work-294a1633367f

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
1

Instant run:

It’s a feature in Android Studio that uses magic to significantly reduce the build and deploy times for incremental code changes during your coding/testing/debugging lifecycle.

This is normal and is part of the Instant Run feature. In theory, subsequent loads should be faster.

You should try re-enabling it and observe for the subsequent runs, you will see the results.

Kashif Faraz Shamsi
  • 513
  • 1
  • 7
  • 21
0

Instant Run allows you to push code changes without building a new APK.