Android永久性ContentObserver [英] Android Persistent ContentObserver
问题描述
内容观察者是否在Android中持久存在?如果我在活动中创建内容观察者,该观察者将继续运行直到我删除观察者.
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.
基本上,我正在创建SMS服务,在接收和发送时,我会将SMS发布到Web服务中,因此无需携带电话即可查看消息.
Basically I am creating a service for SMS, where on receive and on send I post the SMS out to a web service, so I can check my messages with out having my phone.
如果内容观察者与Activity的生活息息相关,那么我该如何创建一个ContentObserver来始终接收有关内容的通知:/sms/
If the content observer is tied to the Activity's life, how can I create a ContentObserver that will always receive notifications on content:/sms/
推荐答案
如果我在活动,观察者会继续吗直到我删除观察者为止.
If I create a content observer in an activity, will that observer continue to run until I remove the observer.
仅当您喜欢泄漏内存,然后直到Android终止该过程.行为良好的活动不会在未在适当的时间取消注册内容观察者的情况下注册(例如, onDestroy()
).
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()
).
如何创建ContentObserver总是会收到通知关于内容:/sms/
how can I create a ContentObserver that will always receive notifications on content:/sms/
SMS内容提供程序不是SDK的一部分.它可能无法在您的手机上运行.在以后的Android版本中,可能会或可能不会.
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.
让 ContentObserver
停留一点的唯一方法是将其放置在 Service
中.但是,服务也不会永远存在,.除此之外,还没有办法让观察者总是接收通知".
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".
对不起!
这篇关于Android永久性ContentObserver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!