I need to retain a complex object in my service, so I can reliably come back to it (it holds updates). Initially I coded it just as a class filed in my Service implementation but I’m observing that the updates object is periodically reset to null which tells me that server class itself is recreated. Can someone recommend lightweight reliable strategy to save and recreate such updates object (I can make it serializable)
Share
When your service is restarted, the
onStop()andonStart()methods are called. You can use theonStop()method to save your data to a persistent location, e.g. an applicationsqlitedatabase. You can restore the data whenonStart()is called.You can read about using an
sqlitedatabase on the android developer website.