onStartCommand after service process is killed when started with START_STICKY

后端 未结 4 1936
你的背包
你的背包 2021-02-13 05:52

I have been reading the Android documentation and I am wondering if anyone can shed some light on what happens to a service instance when a service started with START_STICKY has

4条回答
  •  孤城傲影
    2021-02-13 06:33

    Android will not re-populate 'lost' data values when it re-starts your service so your code needs to cater for this eventuality.

    My approach is to use all non-primitive state variables and to leave them as null. That way I can test for null and take appropriate steps to initialise them as and when.

    I have taken to storing lightweight data that I want to persist across application restarts in the application's preferences.

提交回复
热议问题