Menu

Did your process death test actually kill the process?
📰

Did your process death test actually kill the process?

DEV Community: android·Evgenii Fedin·13 days ago
#nNCx92XQ
#devtoandroid#devto#dev#process#kill
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.