我在哪里结束我的数据库时

我在哪里结束我的数据库时

本文介绍了我在哪里结束我的数据库时,它不断更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的申请,我有同步含有可被用户接受时,他是离线和检查新邮件每隔五秒钟。

In my application, i have Contacts_sync.java class which synchronizes the contacts and offline_Messages.java which contain messages which are received by a user when he was offline and it checks for new messages every five seconds.

现在的问题是,在应用程序启动时,接触同步启动该服务,每五秒钟检查离线消息的另一个服务启动了。

Now the problem is on application start-up, the service for contact synchronization starts and every five seconds another service for checking offline messages starts too.

因此​​,在这种情况下,如何管理关闭数据库。如果我在offlineMessage服务关闭数据库,然后如果有一个联系人同步的持续的过程,那么它给了我数据库关闭错误。

So in this case how do i manage to close the database. If i close the database in offlineMessage service then if there is any ongoing process for Contact synchronization then it gives me database close error.

下面是我的logcat

Here is my Logcat

09-27 13:22:45.125: E/Database(6970): close() was never explicitly called on database 'sipchat.db'
09-27 13:22:45.125: E/Database(6970): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
09-27 13:22:45.125: E/Database(6970):   at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1849)
09-27 13:22:45.125: E/Database(6970):   at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:822)
09-27 13:22:45.125: E/Database(6970):   at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:856)
09-27 13:22:45.125: E/Database(6970):   at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:849)
09-27 13:22:45.125: E/Database(6970):   at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:556)
09-27 13:22:45.125: E/Database(6970):   at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
09-27 13:22:45.125: E/Database(6970):   at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
09-27 13:22:45.125: E/Database(6970):   at org.sipchat.sipua.ui.DatabaseHelper.<init>(DatabaseHelper.java:39)
09-27 13:22:45.125: E/Database(6970):   at org.sipchat.sipua.ui.Contact_sync.onCreate(Contact_sync.java:110)
09-27 13:22:45.125: E/Database(6970):   at android.app.ActivityThread.handleCreateService(ActivityThread.java:1949)
09-27 13:22:45.125: E/Database(6970):   at android.app.ActivityThread.access$2500(ActivityThread.java:117)
09-27 13:22:45.125: E/Database(6970):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:989)
09-27 13:22:45.125: E/Database(6970):   at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 13:22:45.125: E/Database(6970):   at android.os.Looper.loop(Looper.java:130)
09-27 13:22:45.125: E/Database(6970):   at android.app.ActivityThread.main(ActivityThread.java:3687)
09-27 13:22:45.125: E/Database(6970):   at java.lang.reflect.Method.invokeNative(Native Method)
09-27 13:22:45.125: E/Database(6970):   at java.lang.reflect.Method.invoke(Method.java:507)
09-27 13:22:45.125: E/Database(6970):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
09-27 13:22:45.125: E/Database(6970):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
09-27 13:22:45.125: E/Database(6970):   at dalvik.system.NativeStart.main(Native Method)

任何想法和建议,将AP preciated结果
谢谢

Any idea and suggestions will be appreciated
Thanks

推荐答案

不要关闭数据库。 (数据被安全写入为尽早反正持久化存储)。打开它一次,在应用程序启动和重用整个应用程序的生命周期相同的连接。

Don't close the database. There is no need (data gets safely written to persistent storage at the earliest opportunity anyway). Open it once, on application startup, and reuse the same connection throughout your application's lifetime.

请注意,它保持一个单独的连接是非常重要的,也许是作为一个静态你的应用类的成员,因此,它不会触发警告消息你看到当垃圾回收器试图把它清理干净。

Note that it's important to keep a single connection, perhaps as a static member of your Application class, so that it doesn't trigger the warning message you saw when the garbage collector tries to clean it up.

这篇关于我在哪里结束我的数据库时,它不断更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 12:33