XML Oriented GUIs and Performance

Reading the XML developer online developer page , I found the following statement:

Your user interface descriptions are external to your application code, which means that you can modify or adapt it without changing the source code or recompiling.

I know about the many benefits of XML layouts and resources, but since the XML files are located inside the APK, I think there is no real way to change the GUI without repackaging. I mean, most of us use the eclipse ADT and ANT plugins to package applications, so there is no real benefit in not compiling class files (since after changing the resource files, the developer will have to repack the application and create a new APK file). Because of this, it is not possible to relocate the GUI to devices without redeploying the entire APK.

If this assumption was true, then the XML files will be the same throughout the life cycle of the APK file. I suggest that these files (especially layouts) should be parsed and processed at runtime (before the onCreate action), which would be less efficient than creating a GUI programmatically (e.g. in Swing). The layout is usually not a bottleneck, but if I'm right, I see a small waste of time here that could be better used (for example, with animation).

Reading the same page, she states:

When compiling your application, each XML layout file is compiled into a View resource.

Checking one of my APKs, I was looking for a precompiled file inside classes.dex and there was nothing but my java classes and R.class file. The XML layout files are inside the /res/layout folder , and there is a file called resources.arsc which seems to contain information about other resources (strings, icon names) but nothing related to Views, I think (correct me, if I am wrong).

My questions:

  • Are the XML files compiled and to which file?
  • If not, is there a compilation option to completely precompile the layout information into a file for faster download times? (ideally this would be a class file)
  • If not, is there a way to create this file in the first execution and cache it in the application installation folder so that subsequent executions at runtime can read this file instead of XML parsing and have faster download times?

Thanks in advance.

+7
source share
1 answer

If you have gander in the class documentation for LayoutInflater , you'll notice that they say:

For performance reasons, viewing inflation depends heavily on the preprocessing of the XML files that is performed during the build. Therefore, it is currently not possible to use LayoutInflater with an XmlPullParser on top of a regular XML file at run time; it only works with the XmlPullParser returned by the compiled resource ( R.something file .)

So the layout files are really precompiled to some extent, and judging by the above snippet, it will be in the output file R$layout.class (but I'm not 100% sure about this). The precompiled layout file is in your compiled APK package, like /res/layout/<layout_id>.xml . You will notice that extract it and open it in a text editor so that most of the XML text elements are mapped to some binary form.

This will probably be the same kind of compression that you can see in the AndroidManifest.xml files that are packaged in the APK.

+8
source

All Articles