Android and Qt Splash Screen

Since version 12, Android has provided an API for the Android default splash screen. The SplashScreen API provides a way to launch an app with an animation showing the app icon and transitioning to the app. The default Android startup zooms the app icon to the center of the screen and then transitions to the first view of the app. This may cause a jarring user experience if the splash screen is also defined in Qt, as the Qt splash screen is displayed after the Android one. 

The Qt splash screen documentation for Android is not very concise. It consists of few manifest, QML and function documentation entries.

To achieve a smooth transition from the Android splash screen to the Qt splash screen in multi-platform applications, you can minimize the visibility of the Android splash screen. That requires some changes to the Android manifest and resource files. Two examples have been added to show how the Qt splash screen works nicely with an Android startup animation.

Examples can be found on the Qt for Android page.  

Here’s a highlight of the most critical parts of the examples. For a comprehensive description, refer to the example documentation. 

Splash screen activity: 

<activity 
  Android:name=".SplashActivity" 
  Android:exported="true" 
  Android:label="QML Splash Screen Example" 
  Android:theme="@style/splashStartTheme"> 
  <intent-filter> 
    <action Android:name="Android.intent.action.MAIN" /> 
    <category Android:name="Android.intent.category.LAUNCHER" /> 
  </intent-filter> 
</activity> 

In AndroidManifest.xml, the app launches with a dedicated splash screen activity, while the main application activity is included as a separate entry in the manifest.

Splash screen theme: 

<style name="splashStartTheme"> 
  <item name="Android:windowNoTitle">true</item> 
  <item name="Android:windowDisablePreview">true</item> 
  <item name="Android:windowIsTranslucent">true</item> 
</style> 

In the theme XML file, Android:windowDisablePreview set to true removes the initial blank screen, but setting Android:windowIsTranslucent to true is essential, as it enables the Android splash screen to be transparent.

Window translucency is the reason we need two activities in the AndroidManifest. Translucency cannot be changed after view initialization, disabling an application’s ability to change orientation. When a view is translucent, Android picks orientation from the underlying view, which is usually the App Drawer, and it does not change orientation. 

Splash Java class snippet: 

// Set up an OnPreDrawListener to the root view. 
final View content = findViewById(android.R.id.content); 
content.getViewTreeObserver().addOnPreDrawListener( 
    new ViewTreeObserver.OnPreDrawListener() { 
        @Override 
        public boolean onPreDraw() { 
            Intent i = new Intent(SplashActivity.this, QtActivity.class); 
            i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); 
            startActivity(i); 
 
            content.getViewTreeObserver().removeOnPreDrawListener(this); 
            finish(); 
            return true; 
        } 
    });

To start the actual app, we need to wait for Android to set itself up. For that, we define a splash screen activity and override the onCreate function. On that function, we add an onPreDrawListener. The listener is called when the first view is ready to be drawn. At that point, we can launch the Qt activity. For that activity we have defined another theme and set the Android:windowDisablePreview and Android:windowIsTranslucent back to false. 

From then on, the app behaves as a Qt application, showing the Qt splash screen and transitioning to the first application view. See the short videos of the examples running on Pixel 6a.  

Splash screen in QML


Splash screen with XML 

Cross-platform consistency 

The Qt splash screen provides a consistent application launch experience across platforms. If multi-platform consistency is not required, the Android splash screen has the slight advantage of running earlier in the launch sequence. This may be more prominent on less powerful devices, but designing the Qt app wisely will make the difference almost unnoticeable. The documentation covers the details for the implementation of the Android splash screen. 

The use of widgets and QSplashScreen was left out of the examples, but the same activity–theme principle to minimize the Android splash screen applies there, too.  The effort to modernize QSplashScreen is tracked in Jira.

The splash screen examples have been added to the Qt 6.10. The examples are tracked in Jira; any comments and ideas about the feature are welcome. Link to Jira epic. 

 

 

 

 


Comments