Search code examples
android-layoutandroid-jetpack-composeandroid-appwidgetandroid-remoteviewglance-appwidget

How does Jetpack Glance widget works without XML? How does it convert to RemoteViews?


Jetpack released a tool called "Glance" that we can replace RemoteViews XML widgets.

I wonder how it converts compose layouts to RemoteViews.


Solution

  • It does use XML underneath. It uses compose runtime to parse the node-tree, then it takes the corresponding pre-generated XML file and uses remoteviews to modify it's attributes. Then it composes everything into a single RemoteView that is sent to the AppWidget manager.

    You can dive in into the code yourself. It's open source ;) https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:glance