A screen can pass every rotation test you have and still crash the first time Android reclaims the app in the background. Here is one that does:
object Session { lateinit var user : String }
class SessionActivity : ComponentActivity () { override fun onCreate ( savedInstanceState : Bundle ?) { super . onCreate ( savedInstanceState ) val user = Session . user // ... } }
Enter fullscreen mode
Exit fullscreen mode
MainActivity sets Session.user before it opens this screen. Rotate the phone and nothing goes wrong, because the process and the singleton are still alive. Kill the process while the app is in the background and Android recreates SessionActivity directly. MainActivity never runs, and Session.user throws.
The quieter version of this bug doesn't crash. A ViewModel keeps a half-written form in memory, rotation keeps the ViewModel, and process death takes the form with it.
I built process-death-check to catch both.…