I'm writing an app which has a long-running service.
I've written some state-saving code in the service's onDestroy
method.
My intention is that this should be invoked if the service ever gets killed by Android, due to memory pressure.
How can I simulate the service being killed by memory pressure?
I've tried adb shell am force-stop com.example.app
but the service's onDestroy
method was not invoked.
Is onDestroy
a sensible site for service-shutdown-state-saving?
If so, how can I make a service's onDestroy
be invoked by Android, for debugging/testing purposes?