Not exactly compose related, but I noticed all app...
# compose-wear
t
Not exactly compose related, but I noticed all apps when I open show the icon on black background while loading as splash but mine is just a black screen until the app loads. How do I make this splash screen?
y
That example is for Views, maybe we should add a compose one. But it's only trivially different, when you swap out the splash for your content.
Copy code
override fun onCreate(savedInstanceState: Bundle?) {
    setTheme(android.R.style.Theme_DeviceDefault)

    super.onCreate(savedInstanceState)

    setContent {
t
Oh, so it should be before
onCreate
, I was doing it after and somehow it was working 😅
y
It's more likely I'm wrong.
I think I'll move mine after, found other examples with it after also.
y
I did it differently on Android, since the setTheme in onCreate doesn’t produce the desired effect I added a theme to the LaucherActivity to show the splash screen in
AndroidManifest.xml
Copy code
<activity android:name=".LauncherActivity"
    android:theme="@style/SplashTheme"
    android:exported="true">
and the SplashTheme shows a background
Copy code
<style name="SplashTheme" parent="AppTheme">
    <item name="android:windowBackground">@drawable/splash</item>
</style>
and the background drawable is a layer list with a bitmap of app logo
Copy code
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="<http://schemas.android.com/apk/res/android>"
    android:opacity="opaque">
    <item android:drawable="@color/stila_white"/>
    <item android:left="100dp" android:right="100dp" android:top="200dp" android:bottom="200dp">
        <bitmap
            android:src="@drawable/stila_logo_140x195"
            android:gravity="center"/>
    </item>
</layer-list>
This works with Android and the LaunchActivity shows the SplashScreen and launch my MainActivity. Don’t know if there is a better way to do it with Wear OS and Wear Compose.
y
Isn't that the same as the stackoverflow post? The part I linked was purely for clearing it which differs from views to compose.
y
Yeah..very similar. But the stackoverflow post put the spashTheme to the main actviity, and the splash screen of app log would be super fast to disappear. I used an additional activity to show the splashTheme and do some app session initialisation e.g. fetch google login token and some OICD/OAuth2 token in the splash screen activity. Personally, i found it is pleasant for the eye that the splash screen is not super fast disappeared.
y
Ahh, nice. Makes sense.
I might check in if we have actual guidance.
I wonder if I can do something similar for set Content, delaying until ready.
y
As far as i can remember for some android version in view system, the setTheme must be before the setContentView, and sometimes it doesn’t work. But the theme setting of Activity in AndroidManifest happens before the Activity onCreate and it always works. I might be wrong here.
👍🏻 1
If you setContent in compose and delaying it, are you not blocking the main thread?
y
I believe you can call setContent multiple times or later. So would do when it's ready
👍 1