android同步数据库数据

来源:互联网 发布:淘宝嗅觉系是真的吗 编辑:程序博客网 时间:2024/05/16 18:15

        今天遇到一个问题:在一个ActivityGroup和Activity中同时要访问数据库,并且可能都会做修改,那么这是否需要同步?

        首先,ActivityGroup和Activity是否在一个Thread中,Processes and Threads中有这么几句:

When an application component starts and the application does not have any other components running, the Android system starts a new Linux process for the application with a single thread of execution.

By default, all components of the same application run in the same process and thread (called the "main" thread).

         所以,这两个组件应该是在同一个main Thread中的(我对此保持怀疑,或者说,这两个组件的Handler是怎么处理的?),那么同一个线程中是否存在数据同步的问题呢?这个是不会存在的,但是对于不同的对象访问同一个数据库,是否会存在数据冲突?

         事实上,如果只使用一个SqliteDatabase对象是不会有问题的,所以,把SqliteDatabase实现为Singleton应该是一个不错的注意。

原创粉丝点击