I have recently come across an issue in which my Service
method will call onCreate()
multiple times. onDestroy
is not called when this happens. My Service
is just recreated without notice and my Service
's state is reset to as if it started the very first time. I know that Android will kill processes that it needs to free up memory. However, when this happens the lifecycle is still followed and it's trivial to save/restore states. This is just happening in the middle of execution.
What exactly is causing this? From this answer, it says that onCreate is only called when a process is starting which is how I came to this conclusion. This answer says to put the Service in a separate process from the rest of the Application, but this didn't work. It also seems hacky.
This is occurring on Android 4.0.4.