RORK LABJP
TOOLING — Rork's developer repos keep moving: rork-xcode was updated on July 16, rork-device on July 15, and rork-plist on July 13OPUS46 — Claude Opus 4.6 is live in Rork, and Rork Max is built to assemble apps on top of Claude CodeSIM — A cloud iOS simulator runs in the browser, with one click to install on a device and two clicks to publish to the App StoreMAX — Rork Max emits pure Swift rather than React Native, reaching iPhone, iPad, Apple Watch, Apple TV, Vision Pro, and even iMessageNATIVE — That opens up HealthKit, ARKit and LiDAR, NFC, Dynamic Island, Live Activities, 3D through Metal, and on-device inference with Core MLSEED — Rork raised a $15M seed led by Left Lane Capital, with Peak XV and a16z Speedrun joining the roundTOOLING — Rork's developer repos keep moving: rork-xcode was updated on July 16, rork-device on July 15, and rork-plist on July 13OPUS46 — Claude Opus 4.6 is live in Rork, and Rork Max is built to assemble apps on top of Claude CodeSIM — A cloud iOS simulator runs in the browser, with one click to install on a device and two clicks to publish to the App StoreMAX — Rork Max emits pure Swift rather than React Native, reaching iPhone, iPad, Apple Watch, Apple TV, Vision Pro, and even iMessageNATIVE — That opens up HealthKit, ARKit and LiDAR, NFC, Dynamic Island, Live Activities, 3D through Metal, and on-device inference with Core MLSEED — Rork raised a $15M seed led by Left Lane Capital, with Peak XV and a16z Speedrun joining the round
Articles/Dev Tools
Dev Tools/2026-05-16Intermediate

Fixing White Screen on Theme Switch Without recreate() — Lessons from a 50M Download Wallpaper App

How I fixed a white screen bug triggered by theme switching in an Android app — replacing recreate() with an AppRestarter.safeRestart pattern. Lessons from 12 years of indie app development with 50M+ cumulative downloads.

Android43theme switchwhite screenAppRestarterrecreatewallpaper app23indie dev28

When you implement a dark mode toggle in Android, the typical flow is: save the setting, restart the Activity, and have the theme applied. Most sample code uses recreate() for this purpose. In my wallpaper app, which I've been maintaining for over 12 years with 50M+ cumulative downloads, this exact pattern was causing intermittent white screen flashes for some users.

The lesson I've taken from long-running indie app development: bugs are usually symptoms of a deeper design problem. The white screen was telling me something was off about how I was handling Activity recreation in the presence of SDK initialization and heavy image loading.

Why recreate() Causes a White Screen

When recreate() is called, Android destroys the current Activity and creates a new one. The problem is that there's a brief moment between destruction and creation when nothing is rendered — and that gap can become visible.

The conditions that make this noticeable are:

  • Activities that load heavy assets at startup (wallpaper apps are a prime example)
  • Lower-spec devices or older Android versions (6 through 8)
  • SharedPreferences written with apply() instead of commit() — the setting may not be flushed before the Activity restarts

In my case, users of Beautiful HD Wallpapers began reporting brief white flashes during theme changes. The reproduction condition was narrow enough that I couldn't easily catch it myself, which is exactly the kind of bug that lingers in negative reviews for months.

The AppRestarter.safeRestart Pattern

The fix came from rethinking the scope of the restart. Instead of relying on recreate(), which only restarts the current Activity, I moved to a pattern that restarts the entire app process.

// AppRestarter.kt
object AppRestarter {
    fun safeRestart(context: Context, delayMs: Long = 300L) {
        val intent = context.packageManager
            .getLaunchIntentForPackage(context.packageName)
            ?.apply {
                addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
            }
            ?: return
 
        Handler(Looper.getMainLooper()).postDelayed({
            context.startActivity(intent)
            android.os.Process.killProcess(android.os.Process.myPid())
        }, delayMs)
    }
}

The call site is clean and explicit:

// SettingsActivity.kt
fun applyTheme(isDark: Boolean) {
    // Use commit() to guarantee the write before restart
    prefs.edit().putBoolean("dark_mode", isDark).commit()
    AppRestarter.safeRestart(this)
}

recreate() vs. safeRestart: The Real Difference

recreate() restarts only the current Activity. When your app has complex Fragment hierarchies, ViewModel state, or third-party SDKs initialized at the Application level, there's no guarantee that everything lands in a clean state after recreation.

In my wallpaper app, AdMob was being initialized early in the Activity lifecycle. After recreate(), the SDK occasionally landed in a state where it had already received initialization callbacks but the UI hadn't fully rebuilt. This race condition produced the white flash.

AppRestarter.safeRestart() restarts the entire process, which means Application.onCreate() runs again from scratch. Every SDK starts clean. No partial states.

The User Experience Trade-off

Switching to safeRestart means that when a user changes the theme, the app visibly restarts rather than instantly toggling. There's a brief return to the launcher before the app comes back with the new theme applied.

Whether this feels natural depends on the app. For a wallpaper app, theme switching is a rare, deliberate action. A clean restart actually feels more intentional than a brief white flash. After shipping this fix in v2.1.0, the complaint rate around theme switching in user reviews dropped noticeably.

If 300ms isn't enough delay on your target devices, extending to 500ms is safe.

Applying This to Rork Max Projects

When Rork Max generates an Android project, theme management typically goes through Context or a Theme Provider. If you're building a production app with Rork and want to implement theme switching reliably, here's what to verify before shipping:

  • Confirm the Activity extends AppCompatActivity
  • Check whether theme preferences are stored in SharedPreferences or Jetpack Datastore
  • Look at where SDK initialization (AdMob, Firebase, etc.) happens — is it in Application.onCreate() or the Activity?

Rork-generated settings screens tend to implement theme switching with recreate() or equivalent behavior by default. For production use, it's worth refactoring to the safeRestart pattern before launch.

Building Apps That Last

My late grandfathers were both temple carpenters. The belief I grew up watching them practice was that craftsmanship applied to things meant to last is itself a form of devotion. That sensibility carries into how I approach app maintenance.

recreate() works on most devices most of the time. But collecting user reviews over time and noticing a pattern of "occasional white screen" reports is how you find the problems that device testing in ideal conditions will never surface.

This is true whether you're writing Android code from scratch or building with Rork. The quality comes from the small, careful fixes — understanding why something works the way it does, and choosing the approach that holds up under real conditions.

If you're seeing white screen reports related to theme switching, start by looking at recreate() and how SharedPreferences writes are timed around it. That's where the answer usually is.

Share

Thank You for Reading

Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

If you found this article helpful, a small tip ($1.50) would mean a lot to us. Your support helps keep this site ad-free and covers server and hosting costs.

Related Articles

Dev Tools2026-05-18
Adapting Your Rork iOS App to iPhone Air and 17 Pro Series — Layout Patterns for 2026's New Resolutions
When iPhone Air added a new point resolution to the mix, existing Rork apps needed layout adjustments. Based on updating 4 iOS apps simultaneously — including Beautiful HD Wallpapers with 50M+ downloads — this guide covers device constant management, Safe Area handling, and full-screen wallpaper display fixes.
Dev Tools2026-05-17
Images Vanishing After Play Store Release — Fixing drawable-nodpi in Rork Android Apps
After publishing a Rork-generated Android app to the Play Store, images disappeared on low-density devices. The culprit: Play Store's density APK splits and how they handle drawable-nodpi resources. A real-world fix from 12 years of app development.
Dev Tools2026-04-11
Building a Live Streaming App with Rork and Agora SDK — Real-Time Video, Gifting, and Monetization
Build a production-ready live streaming app using Rork and Agora SDK. Covers iOS/Android setup, host and audience roles, real-time chat, gift monetization, and scaling strategies with full code examples.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →