Android Persistent ContentObserver

前端 未结 2 978
余生分开走
余生分开走 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

    If I create a content observer in an activity, will that observer continue to run until I remove the observer.

    Only if you like leaking memory, and then only until Android terminates the process. Well-behaved activities will not register content observers without unregistering them at an appropriate time (e.g., onDestroy()).

    how can I create a ContentObserver that will always receive notifications on content:/sms/

    The SMS content provider is not part of the SDK. It may or may not work on your phone. It may or may not work in future versions of Android.

    The only way to have a ContentObserver that sticks around for a bit is to have it be in a Service. However, services do not live forever, either. Beyond that, there is no way to have an observer "always receive notifications".

    Sorry!

提交回复
热议问题