如何进行网站检查,中企动力销售好出单吗,软件推广赚钱,开发一个手游游戏要多少钱我们在ContentProvider的insert,update,delete等改变之后调用getContext().getContentResolver().notifyChange(uri, null);这样就通知那些监测databases变化的observer了#xff0c;而你的observer可以在一个service里面注册。
以Downloadmanger为例子#xff1a; 定义Cont…我们在ContentProvider的insert,update,delete等改变之后调用getContext().getContentResolver().notifyChange(uri, null);这样就通知那些监测databases变化的observer了而你的observer可以在一个service里面注册。
以Downloadmanger为例子 定义ContentObserver并且在onChange里做你想做的事情。 Java代码 /** * Receives notifications when the data in the content provider changes */ private class DownloadManagerContentObserver extends ContentObserver { public DownloadManagerContentObserver() { super(new Handler()); } /** * Receives notification when the data in the observed content * provider changes. */ public void onChange(final boolean selfChange) { if (Constants.LOGVV) { Log.v(Constants.TAG, Service ContentObserver received notification); } updateFromProvider(); } }
在DownloadService的onCreate中注册Java代码 public void onCreate() { super.onCreate(); if (Constants.LOGVV) { Log.v(Constants.TAG, Service onCreate); } mDownloads Lists.newArrayList(); mObserver new DownloadManagerContentObserver(); getContentResolver().registerContentObserver(Downloads.CONTENT_URI, true, mObserver); .....} Java代码 /** * Cleans up when the service is destroyed */ public void onDestroy() { getContentResolver().unregisterContentObserver(mObserver); if (Constants.LOGVV) { Log.v(Constants.TAG, Service onDestroy); } super.onDestroy(); }
可以参考以下文章http://hi.baidu.com/lck0502/blog/item/a818258f304b61e0f01f3691.html