How can I save data from Android service?

前端 未结 4 864
眼角桃花
眼角桃花 2021-01-13 14:21

I have a service that collects data, can I save the data in case of reboot or any other action that will restart the service, and how can I do it?

4条回答
  •  -上瘾入骨i
    2021-01-13 14:48

    Android Services have a lifecycle like its Activities. Refer to the documentation for proper callbacks to save state before a service is shutdown.

    Might I recommend the onDestroy() method.

提交回复
热议问题