Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 2.0: Why does Instant Run not work when modifying xml layout resources?

Tags:

This is a very new feature, as Android Studio 2.0 is only available in the canary release channel, however I was hoping someone could further explain how the Instant Run feature works.

If I modify code within my Java classes (Activities, Fragments, etc.) then Instant Run works smoothly. It keeps the instance of the app running and swaps out code behind the scenes, greatly improving the time it takes for me to test (which is awesome, btw).

However, if I modify existing layout xml resources, then it has to recompile a build and deploy it. So my questions are:

  1. Why does it need to rebuild when modifying existing layout xml resources?
  2. Are there plans for the future to allow hot-swapping XML resources so that I don't have to rebuild every time I want to see a change in layout? (Although, I know I can just view changes in the Design view).

Question #1 is more important to me at the moment, because I'd like to understand how it all works. Also, congratulations to the Android Studio team. The IDE has come a long way. The performance improvements are life-changing.

like image 467
w3bshark Avatar asked Nov 24 '15 19:11

w3bshark


People also ask

Does Android studio still have instant run?

Instant Run is currently available only in Android Studio 2.0, and higher. We will continue to improve the feature in subsequent releases.

What are some advantages to authoring Android UI layouts using XML?

Android provides a very flexible way to display layouts using XML-based layouts. This helps us create apps while keeping the layout and logic completely separate. This makes it very easy for us to change the layout even after the application is written, without having any changes in the programming logic.

Which is the default layout for XML in Android Studio?

The Constraint layout is the default layout used in Android.

What is Activity_main XML in Android Studio?

The Main Activity File activity_main refers to the activity_main. xml file located in the res/layout folder. The onCreate() method is one of many methods that are figured when an activity is loaded.


2 Answers

enter image description here

As you know all the resources used in your xml file are converted into static fields in R class. As per the information got from http://tools.android.com/tech-docs/instant-run changing static fields are not supported by instant Run.

like image 196
San Avatar answered Oct 03 '22 05:10

San


Just a little hint. When I switched from Android Studio 1.5 to 2.0 (stable) the new Instant Run didn't work with layout changes. I tried Run > Clean and rerun app and I solved, since that moment Instant Run works.

like image 45
fireb86 Avatar answered Oct 03 '22 05:10

fireb86