0

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.

Community
  • 1
  • 1
DeeV
  • 35,865
  • 9
  • 108
  • 95
  • Have you tried making your service a singleton? That way you can only have one instance at a time? – Eenvincible Mar 06 '14 at 01:59
  • @Eenvincible: I may need some sort of Singleton to more easily save the state, but I'm concerned as to why this is happening in the first place. – DeeV Mar 06 '14 at 02:09

0 Answers0