Android Persistent ContentObserver

前端 未结 2 979
余生分开走
余生分开走 2021-01-01 07:42

Are content observers persistent in Android? If I create a content observer in an activity, will that observer continue to run until I remove the observer.

Basica

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 07:45

    I have tried many ways to make this work, the only way (non-ideal) that has worked is to have a foreground service which runs even after your activity is destroyed. The foreground service registers the contentobserver. the downside is foreground services require a permanent notification.

    I am still looking for a way to have a background service run without it being recycled, and it gets harder and harder. Stuff like "sticky" and broadcast receiver to restart service are no longer working.

提交回复
热议问题