Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QML Application Shows Blank Screen After Background Termination on Android 15
Forum Updated to NodeBB v4.3 + New Features

QML Application Shows Blank Screen After Background Termination on Android 15

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 4 Posters 470 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NatureYellow
    wrote on 21 Mar 2025, 05:57 last edited by
    #1

    Description:
    My QML-based Android app works normally when launched, but if it stays in the background for an extended period (e.g., 30+ minutes), reopening it results in a blank screen. The UI components disappear entirely, and only a white/black background is visible. This issue occurs on Android 15 devices.

    Key Observations:

    The app uses QtFullscreenActivity with the following manifest configuration:

    <activity
        android:name="org.qtproject.qt.android.bindings.QtFullscreenActivity"
        android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
        android:launchMode="singleTask"
        android:screenOrientation="portrait">
    </activity>
    

    Logs show OpenGL context destruction when entering the background:

    D/HWUI    : RenderThread::destroyRenderingContext: this=0xb400007591894480
    D/HWUI    : SkiaOpenGLPipeline::onContextDestroyed: this=0xb40000768a718d00
    D/HWUI    : EglManager::destroy: mEglDisplay=0xb40000768a716500, mEglContext=0xb40000768a48f900, mCurrentSurface=0x0
    

    Although there is a crash report when running in Qt Creator, the QML engine can restore the UI state. However, when running independently on the phone and the application is in the background for too long, the QML engine cannot restore the UI state, leaving only a blank space when entering again.

    Request for Guidance:

    • How can I enforce state persistence for QML components (e.g., StackView navigation history)?
    • Are there manifest flags or Qt-specific configurations to prevent OpenGL context destruction?
    • Should I replace QtFullscreenActivity with a custom lifecycle-aware Activity?
      Full Manifest:
    //AndroidManifest.xml
    <?xml version="1.0"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
        package="org.ChengWang.YellowTown" 
        android:installLocation="auto"
        android:versionCode="1" 
        android:versionName="0.2.1">
        
        <supports-screens 
            android:anyDensity="true" 
            android:largeScreens="true" 
            android:normalScreens="true" 
            android:smallScreens="true"/>
        
        <application 
            android:name="org.qtproject.qt.android.bindings.QtApplication" 
            android:hardwareAccelerated="true" 
            android:label="城网" 
            android:requestLegacyExternalStorage="true" 
            android:allowBackup="true" 
            android:fullBackupOnly="false" 
            android:icon="@drawable/icon">
            
            <activity 
                android:name="org.qtproject.qt.android.bindings.QtFullscreenActivity" 
                android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" 
                android:launchMode="singleTask" 
                android:screenOrientation="portrait" 
                android:exported="true" 
                android:label="城网">
                
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
                
                <meta-data 
                    android:name="android.app.lib_name" 
                    android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
                <meta-data 
                    android:name="android.app.arguments" 
                    android:value="-- %%INSERT_APP_ARGUMENTS%% --"/>
            </activity>
            
            <provider 
                android:name="androidx.core.content.FileProvider" 
                android:authorities="${applicationId}.qtprovider" 
                android:exported="false" 
                android:grantUriPermissions="true">
                <meta-data 
                    android:name="android.support.FILE_PROVIDER_PATHS" 
                    android:resource="@xml/qtprovider_paths"/>
            </provider>
        </application>
        
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    </manifest>
    
    //QtFullscreenActivity.java
    package  org.qtproject.qt.android.bindings;
    
    import android.content.Context;
    import android.content.Intent;
    import android.app.PendingIntent;
    import android.util.Log;
    import android.os.Bundle;
    import android.os.Build;
    import android.graphics.Color;
    import android.view.WindowManager;
    import android.view.View;
    
    // 继承 QtActivity 类
    public class QtFullscreenActivity extends org.qtproject.qt.android.bindings.QtActivity {
        private final static String TAG = "QtFullscreen";
        private static Context context;
    
        @Override
        // 重写 onCreate 方法
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // 去除标题导航栏
            context = getApplicationContext();
            // 设置状态栏全透明
            this.setStatusBarFullTransparent();
        }
    
        // 全局获取Context
        public static Context getContext() {
            return context;
        }
    
        // 全透状态栏
        private void setStatusBarFullTransparent() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // 透明状态栏
                // 状态栏字体设置为深色,SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 为SDK23增加
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    
                // 部分机型的statusbar会有半透明的黑色背景
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                getWindow().setStatusBarColor(Color.TRANSPARENT); // SDK21
            }
        }
    
        // 非全透,带颜色的状态栏,需要指定颜色
        private void setStatusBarColor(String color) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                // 需要安卓版本大于5.0以上
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                getWindow().setStatusBarColor(Color.parseColor(color));
            }
        }
    }
    
    1 Reply Last reply
    0
    • P Offline
      P Offline
      pypi
      wrote on 31 Mar 2025, 20:53 last edited by
      #2

      I had a similar looking problem (Qt app displaying blank screen after being backgrounded). Maybe you just need to update the Qt version you are using?

      https://bugreports.qt.io/browse/QTBUG-132085

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zvoopz
        wrote on 1 Apr 2025, 08:26 last edited by
        #3

        My android built app suffers the same issue with blank screen after being backgrounded.
        qmake, OS Android 13 Qt version - 6.8.2

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Michel de Boer
          wrote on 2 Apr 2025, 17:05 last edited by
          #4

          Interesting, I received complaints from some users that this happens with and Android app I developed. They experience a grey screen on Android 15 (Qt 6.8.3) on Pixel phones. I have not experienced this myself on Android 14 on a Samsung Galaxy S22.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved