I’ve been fiddling with CB lite for a while now and I’m starting to encounter a few problems as a result of not approaching it from the right angle. I basically have a couple of activities that use the database and I haven’t been able to handle it well. What I did at first was to create a new instance of the StorageManager (which is the class that provides the database) on both activities and, since the database would be the same, I thought this would be ok for synchronization. This has created a lot of problems (specially when restarting the Replication pusher every time I resume an activity) and I thought it would be better to look it up here in the forum.
I’ve seen some recommendations about using a singleton or a content provider, as well as having a service running in the background doing all the syncing.
Using a simpleton is not recommended in android unless you use a library that manages the threads, and making a content provider seems like overkill to me.
Is there a sample case for this that I haven’t come by yet? am I missing something?
Is it alright to use the same CBL in 2 applications simultaneously, Will Database change listeners and live queries work if both applications are using the same CBL?
Why I am asking this as we are looking to create a back ground service which will keep the device in sync with the server even if the App is not active. But then will App get all the change listener events if the data is synced by background service?
The database can be accessed from multiple processes, but notifications and LiveQueries won’t trigger if a change was made by another process.
We hope to fix this, since it can be a useful design, but haven’t gotten to it yet.
If you need the app to receive updates at any time, it’s better for the device’s battery life if you use push notifications to wake up the app, instead of having a process checking the server all the time.
@jens The issue is if the app stops for some period of time it goes for _rev_diff calls. and in my case it is 480 calls to sync gateway. That blocks other data which I need to send. Hence looking for a background app.
What I am doing is populating CBL with syncing it in a java app and then provide this CBL as zip to app when they launch for the first time. is it the reason for _rev_diff calls? If yes then how can I make sure that these calls are done for the first time and not again if all data is already there (last sequence number).