What is the wear os app lifecycle? Like when does ...
# compose-wear
a
What is the wear os app lifecycle? Like when does an app go into start/resume/pause/stop ? If it's only OS driven, is there a way to trigger this manually ?
a
What are you trying to do?
a
I'm trying to test a scenario out. Apparently I have stateflow causing me an NPE. class VM(val x: X) { init { viewmodelScope.launch { x.getStateFlow().collect { y.update {} } } } val y = MutableStateFlow(0) }
Apparently the solution is to move the declaration of y to be above the init block
So I wanted to repro this, and it seems to be happening during onPause onStop and onSavedInstanceState
a
You can press the "home" button to background the app which should trigger onPause/onStop. On the emulator either button 1 or 2 will work (one is home the other is recent apps but I don't recall which)
Similarly the palm button should turn the screen off and it should go through onPause/onStop
a
Okay ! I'll try those
Is there a way to force the app to go through an app kill and to trigger onSavedInstanceState ?
I've been using adb shell am start -S -n ...
a
Developer settings might include "don't keep activities" like it does on phones but I'm not sure. In that case, I think pressing home will kill the activity/app
a
I didn't see it in the wear settings :(
g
follow these steps: 1. launch your app 2. push the button 1 from the emulator to put your app in background - this step is important 3. kill your app via adb:
adb shell am kill <your app package>
4. from the recents menu, open your app
just tested with the sample app from horologist, added this log to
onCreate
in`MainActivity`:
Copy code
Log.d("REMOVEME", "savedInstanceState null? ${savedInstanceState == null}")
followed the steps above and could can see in logcat:
Copy code
---------------------------- PROCESS STARTED (8852) for package com.google.android.horologist.sample.debug ----------------------------
2022-11-24 19:35:16.345  8852-8852  REMOVEME                com...droid.horologist.sample.debug  D  savedInstanceState null? true
---------------------------- PROCESS ENDED (8852) for package com.google.android.horologist.sample.debug ----------------------------
---------------------------- PROCESS STARTED (8913) for package com.google.android.horologist.sample.debug ----------------------------
2022-11-24 19:35:29.926  8913-8913  REMOVEME                com...droid.horologist.sample.debug  D  savedInstanceState null? false
f
press on the secondary button to display the recent app and do a long press on the one you want to kill
g
that doesn't simulate the process death, just tried and
savedInstanceState
is null after launching it
a
Thanks @Gustavo Pagani this works and helped debug !