onStartCommand after service process is killed when started with START_STICKY

后端 未结 4 1728
天命终不由人
天命终不由人 2021-02-13 06:15

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:54

    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.

提交回复
热议问题