https://kotlinlang.org logo
#compose
Title
# compose
m

Mofe Ejegi

02/28/2024, 11:15 AM
I have a question concerning Compose Multiplatform's default setup in the
AndroidManifest.xml
.
Copy code
<activity
  android:exported="true"  android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
  android:name=".MainActivity"
>
Why is the activity given the responsibility of handling all possible config changes? I've grown accustomed to handling config changes in all my years of Android development so I'm curious about the possible drawbacks of this approach, especially regarding fetching/updating resources (strings, drawables, etc). Is there something unique about Compose Multiplatform (compared to the usual Android development) that allows this approach work well?
m

Michael Paus

02/28/2024, 11:21 AM
Compose is supposed to handle these changes for you automatically. So, you don’t have to care anymore.
m

Mofe Ejegi

02/28/2024, 11:23 AM
Thank you, so if I were building a new modern Android application, using Jetpack Compose, single activity and no xml layouts, would this still be acceptable?
m

Michael Paus

02/28/2024, 11:25 AM
Actually it only works automatically in this way in a pure Compose application.
m

Mofe Ejegi

02/28/2024, 11:33 AM
That makes sense. Thanks again. I'm guessing the example I mentioned wouldn't count as a "pure Compose application"
s

Stylianos Gakis

02/28/2024, 12:49 PM
Be careful though, there are still things that will silently fail to work which you would not expect. I got this https://issuetracker.google.com/issues/321896385 and this https://issuetracker.google.com/issues/292204649 just from a quick search, but I’ve definitely had to remove entries from the list of
configChanges
before because it introduced problems. And all this has been in a pure compose app.
m

Michael Paus

02/28/2024, 2:50 PM
I am talking about how Compose is designed and how it is supposed to work. Of course there may be and actually are bugs which deviate from the expected behaviour but hopefully these bugs will be fixed soon.
s

Stylianos Gakis

03/10/2024, 6:17 PM
The ideal world sounds nice, but I would absolutely not recommend doing this in a real app yet.
c

Colton Idle

03/10/2024, 6:28 PM
i currently do this in one of my apps, but still test state restoration and config changes and that list doesn't cover all config changes
m

Michael Paus

03/10/2024, 6:34 PM
The current list is
Copy code
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|layoutDirection|locale|mcc|navigation|smallestScreenSize|touchscreen|uiMode"
which you get automatically when you create a new project with the Compose Multiplatform Wizard.
s

Stylianos Gakis

03/10/2024, 6:41 PM
My concerns are not even about missing one of them or that state restoration doesn't work. It is as I said above that this starts introducing subtle bugs in your codebase that you are most likely will miss