其实这文章讲的就是通过ContentObserver来监测Databases的改变,并且做出相应的处理。
但对Databases的改变,除了可以通过ContentObserver来监测外,还可以通过DatasetObserver来监测。那我们来看看它们之间的区别
1,ContentObserver
Receives call backs for changes to content. Must be implemented by objects which are added to a ContentObservable.
接受回调去改变Content.
其实ContentObserver主要是通过Uri来监测特定的Databases的表:
比如:
public class TestContentObserver extends Activity {
MyContentObserver mco;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mco=new MyContentObserver(new MyHandler());
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
getApplicationContext().getContentResolver().registerContentObserver(Contacts.CONTENT_URI, true, mco);
}
class MyHandler extends Handler{
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
}
};
class MyContentObserver extends ContentObserver{
public MyContentObserver(Handler handler) {
super(handler);
// TODO Auto-generated constructor stub
}
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
System.out.println("onChange "+selfChange);
}
@Override
public boolean deliverSelfNotifications() {
// TODO Auto-generated method stub
return super.deliverSelfNotifications();
//return true;
}
};
}
registerContentObserver(Contacts.CONTENT_URI, true, mco);通过对Contacts.CONTENT_URI的监测,当Contacts发生变化就会call back回调mco里面的onChange方法来处理变化。
2,DatasetObserver
Receives call backs when a data set has been changed, or made invalid. The typically data sets that are observed are Cursors or Adapters. DataSetObserver must be implemented by objects which are added to a DataSetObservable.
DatasetObserver当数据集改变或者无效时,就会回调相应的函数做出处理,而典型的数据集就是cursor或者adapters.
这就是说通过cursor或者adapters的改变来做出相应的处理。
比如:QuickSearchBox中的SuggestionsAdapter
mSuggestionsAdapter.registerDataSetObserver(new SuggestionsObserver()); private class SuggestionsObserver extends DataSetObserver {
@Override
public void onChanged() {
updateInputMethodSuggestions();
}
}
分享到:
相关推荐
Hadoop databases: Hive, Impala, Spark, Presto For ORACLE DBAs
Administering Microsoft SQL Server 2012 Databases Exam : 070-462
Graph Databases - New Opportunities for Connected Data(2nd) 英文无水印pdf 第2版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本...
Fuzzy Databases: Modeling, Design And Implementation by Jose Galindo (Author), Angelica Urrutia (Editor), Mario Piattini (Editor) Publisher: Idea Group Publishing (October 19, 2005) | ISBN-10: ...
In this paper we present Ontop, an open-source Ontology Based Data Access (OBDA) system that allows for querying ...and OWL 2 QL and RDFS ontologies), and its support for all major relational databases
Deciding to use a relational database was once truly a no-brainer, and the various commercial relational databases competed on price, performance, reliability, and ease of use rather than on ...
向技术从业者(包括开发人员,数据库专业人员和技术决策者)介绍图形和图形数据库。
根据菜鸟教程Django教程学习,运行”python manage.py migrate” 报错,...1.只需要修改setting.py文件里的DATABASES即可:(按照图中注释修改) DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql',
Databases:Kalmasoft数据库
Android 将assets中的数据库导入到项目中databases https://blog.csdn.net/qq_31939617/article/details/80929543
资料库 ... 在这里,您可以找到该项目的源代码和文档。 该项目将完全支持MongoDB,MySQL,PostgreSQL,H2和SQLITE。 如何安装 玛文 ... implementation 'com.github.celesteoficial:databases:VERSI
There are many different databases: from the small and useful SQLite to the powerful Teradata. But, there are only a few articles that explain how a database works. You can google by yourself “how ...
Visual C# and Databases is a tutorial that provides a detailed introduction to using Visual C# for accessing and maintaining databases. Topics covered include: database structure, database design, ...
docker-postgresql-multiple-databases:将多个数据库与官方PostgreSQL Docker映像一起使用
Visual Basic and Databases A Step By Step Database Programming Tutorial 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
2018-FL分布式医学数据研究-Federated Learning in Distributed Medical Databases Meta-Analysis of Large-Scale Subcortical Brain Data1
This provides unique insight into the challenges of scaling web databases, which in turn has driven the development of MySQL Cluster, integrating key technologies to enable the scaling of rapidly ...
Graph Databases.pdf
#databases 这是我在学生时代完成的一个项目。 这个项目是与一对合作的。