New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alternative for ContentProvider #45
Comments
@rafaelekol what is your concern with using ContentProviders? To be honest, I do not have much experience using an SQLite database directly. My main concern would be using the same SQLite database from multiple processes simultaneously without a ContentProvider. There seem to be some stackoverflow threads saying it at least not straightforward (read/write locks producing errors) http://stackoverflow.com/questions/5248319/database-handling-with-2-processes and http://stackoverflow.com/questions/12407433/multiple-access-to-sqlite-database-in-android. Do you know if this is a limitation of directly accessing the SQLite database without ContentProviders? |
It seems that SQLBrite does also support ContentProviders as a source for observables, though of course it uses cursors internally. It might be an interesting option, even if it still requires the actual ContentProvider as well as the code to parse the query results. |
I haven't encountered such problems with SQLite yet, but thank you for advice. |
For the boilerplate I have an intermediate solutions that I am planning to extract into a library. It would at least make it cleaner to declare the ContentProviders. It might already be enough to make the architecture easily adoptable. However, I did notice that even in that case it might be a good idea to use SQLBrite and database Cursors instead of the onChange event. I will look into using plain SQLite databases, though, as it might be an easy alternative. The other thing I am thinking is using in-memory databases that do not need a schema at all. If you do not need the caching or inter-process operability, it could be a good light weight solution for many apps. |
OK, I will check in-memory database solution too, meanwhile I found cool new library for database https://github.com/pushtorefresh/storio . I think it has big potential, especially with Reactive programming. |
Oh nice, that's sounds promising! We had an implementation of the in-memory store, but we replaced it with the ones that base on ContentProviders because of the revised architecture that is being updated. The plan is to do all the network requests in a separate service, which would mean it's not possible to use an in-memory one since it cannot be shared between processes. Maybe another example repository with a less ambitious architecture would be in place. |
afaik this project makes emphasis on widget tools and widgets don't work with sqlite dbs directly, but through contentprovider api |
why not use okhttp-cache to cache data? |
@muyiou ContentProviders in this architecture are not only used for caching but also for propagating the updated data. Disk cache for http requests is usually enough for caching data between application launches, but the propagation mechanism would be actually quite difficult to implement. On a side note, I had a chat with the maintainer of https://github.com/SimonVT/schematic and it seems it is the best solution available for declaring content providers in a convenient way with annotations. With the Schematic library it should be an acceptably low effort to implement a ContentProvider. |
Just stumbled upon this |
Resolved with pull request #73. |
You prepared a great example project. But I have one issue. Can we use alternative ways to observe data changes instead of ContentProvider. For example SQLBrite, or simple SQL query?
The text was updated successfully, but these errors were encountered: