force-closing an app with a service: onDestroy() is not called in service?

前端 未结 3 1638
时光取名叫无心
时光取名叫无心 2021-01-18 06:05

I\'ve implemented a sticky service and when I force close the app I see that the Activity\'s onDestroy() is called. But the service doesn\'t apparently do anything.


相关标签:
3条回答
  • 2021-01-18 06:43

    Expecting a service to be force closed seems kinda weird to me. Anyways if the process is terminated i would expect any open file handle to be closed by the linux subsystem.

    Also as stated by CommonsWare onDestroy isn't guaranteed in any case.

    0 讨论(0)
  • 2021-01-18 06:47

    It's worse. onDestroy is only called in emulator environment (for testing), but never on a real phone....

    And exactly as @mibollmba said - files will be closed when process dies. No need to handle file close.

    0 讨论(0)
  • 2021-01-18 06:55

    how do I know when the service is force closed?

    You don't. onDestroy() is not guaranteed to be called, on any component.

    I need to trap that event so that I can close files.

    Then don't leave them open.

    0 讨论(0)
提交回复
热议问题