connglli / blog-notes

My personal notes ✍️
MIT License
32 stars 2 forks source link

Android Layout Inflating #100

Open connglli opened 4 years ago

connglli commented 4 years ago

Overview

In Android, each view written in xml layout is parsed and instantiated by LayoutInflater. To get LayoutInflater, one often uses the following three manners:

Actually, the former two APIs in the end invokes the third API

In essence, Layout Inflater Service is not actually a system service like AMS, there are no actual services in the system server, but only wants to be managed in a system-service-alike manner, i.e., managed by Context#getSystemService() (but only registered to SystemServiceRegistry, not ServiceManager, and further not register to servicemanager)

To inflate a layout, one uses LayoutInflate#inflate(). In detail, LayoutInflater#inflate():

  1. firstly tries to load an precompiled view, and return that, if not exists,
  2. then uses XmlResourceParser to parse the XML, reading the classes and attributes, and iterately using reflection to create Views

AttributeSet, XmlResourceParser

:warning: TO BE ADDED

References

Live Layout Update (DynamicLayoutInspector)

Read also #101

The Live Layout Update of Android Studio uses poll mechanism. That is, there exists an ART agent daemon installed on the device, loaded to the app's process, and continuously crawling the view hierarchy, and sending tp and caching in the profiler daemon. Android Studio polls the daemon for the new updates (see following architecture)

|AS| --poll--> |Daemon| <--send-- |Agent| --poll--> |App|

This involves several questions:

  1. When and how the daemon is created, and started?
  2. When and how the agent is created, and started?
  3. When does Android Studio establish the connection to the daemon?
  4. What does Android Studio poll?

Implementation

Why ART TI?

To load the agent in the same process as the app, so that can directly use the app's inner states