Android闪屏页帧丢失求助:闪屏被直接跳转至主页面
Hey there, let's break down why your splash screen is getting skipped and those "Skipping 88 frames" warnings are popping up—even with small image files! The core issue here is that your main (UI) thread is being blocked by some work, so the system skips rendering the splash screen to get to the main activity faster. Here are the most effective fixes:
1. Use Android's Official Splash Screen API (Recommended)
This is the modern, system-level way to implement splash screens, and it eliminates most frame-drop/skipping issues by design. It works natively on Android 12+, and you can use the androidx core library to support older versions down to Android 6.0.
Steps to implement:
- Create a combined splash drawable (
res/drawable/splash_screen.xml) for your background and logo:<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- Background layer --> <item android:drawable="@drawable/your_background_image"/> <!-- Centered logo layer --> <item> <bitmap android:gravity="center" android:src="@drawable/your_logo_image"/> </item> </layer-list> - Define a splash theme in
res/values/styles.xml:<style name="SplashTheme" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@drawable/splash_screen</item> <item name="windowSplashScreenAnimationDuration">2000</item> <item name="postSplashScreenTheme">@style/YourMainActivityTheme</item> </style> - Apply this theme to your launch activity in
AndroidManifest.xml:<activity android:name=".SplashActivity" android:theme="@style/SplashTheme"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> - Handle the splash screen transition in your
SplashActivity:class SplashActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Initialize the system splash screen val splashScreen = installSplashScreen() // Optional: Keep splash visible if you need to wait for data loading splashScreen.setKeepOnScreenCondition { // Return true until your loading is complete, false to dismiss false // Replace with your actual loading check } // Navigate to main activity after a delay Handler(Looper.getMainLooper()).postDelayed({ startActivity(Intent(this, MainActivity::class.java)) finish() }, 2000) // Adjust delay to your preference } }
2. Fix Your Existing ImageView-Based Setup
If you can't switch to the official API right now, here's how to rescue your current implementation:
- Move all heavy work off the main thread: Any initialization (like SDK setup, data fetching) should run in a coroutine, background thread, or
AsyncTask—never directly inonCreateof your splash activity. - Load images asynchronously: Even small images can cause minor main thread blocking during decoding. Use a library like Glide to load them without blocking the UI:
// In your SplashActivity's onCreate Glide.with(this) .load(R.drawable.your_background_image) .into(backgroundImageView) Glide.with(this) .load(R.drawable.your_logo_image) .into(logoImageView) // Start the delay only after both images are loaded backgroundImageView.post { logoImageView.post { Handler(Looper.getMainLooper()).postDelayed({ startActivity(Intent(this, MainActivity::class.java)) finish() }, 2000) } } - Simplify your layout: Make sure your splash layout has minimal nesting and no unnecessary views—this cuts down on the time it takes to inflate the layout on the main thread.
3. Diagnose Hidden Main Thread Blockers
Use Android Studio's Profiler (View > Tool Windows > Profiler) to dig into what's blocking your main thread. Check the CPU tab for long-running tasks—even a small unexpected operation can cause frame skips and splash screen skipping.
内容的提问来源于stack exchange,提问作者jp singh

