Is it possible to successfully use Sqlite on Android without also having to use a ContentProvider?
Can someone show me a sample that doesn't use ContentProvider?
And if it is indeed true that Sqlite can be successfully used without it, what are examples of cases where ContentProvider would be necessary?
This site does an excellent job describing how to use SQLite in Android without managing to ever once use the term 'ContentProvider.'
A simple Google search such as Android SQLite tutorial -"ContentProvider" will show many many more examples.
Google is your friend.
You need to be aware that SQLite database isn't thread safe, so if you intend to have more than the one thread running at any time accessing the database, you'll definitely run into more problems than in implementing a ContentProvider.
I strongly recommend having a ContentProvider as you can bake all the difficult SQL that cannot be mapped to ContentProvider queries into URIs instead.
Related
I want to know how i can make my app work in offline mode and store the data on a local database on the android device.
I am using mongodb database and fetching the data by using JSON Parsing.
What should i use to make my app run in offline mode and also update the changes made on the server ?
Which tools should i use ,also which is the best and easy method to implement this?
Thanks in advance.
first you create local SQLite Date Base
in that create one extra column like "noNet" ...
In this column you save your data when phone in offline mode and then send data to web server when phone is online
This question is a bit older now, but I'd like to add what I believe is a good architecture approach to solving this.
Take a look at the tech talk given by Yigit and Adam at the Android Dev summit. https://plus.google.com/+AndroidDevelopers/posts/3C4GPowmWLb
Seems the core components are:
Job Scheduler/Queue, via https://github.com/yigit/android-priority-jobqueue
DBFlow to make interaction with the SQLite database easier: https://github.com/Raizlabs/DBFlow
And an EventBus https://github.com/greenrobot/EventBus to easily broadcast when the actual jobs complete (so the UI and other components can be notified).
Those 3 together get you most of what you will probably need. Their tech talk (first link above) really details these things better, and there's a final example application you can take a look at as well: https://github.com/yigit/dev-summit-architecture-demo
If you have an option, you can go for couchdb or couchbase which provide couchlite for android and sync is taken care by itself.
you can also refer this thread here SQLite on Android and MongoDB with synchronization
I'm reading the official documentation from android's content providers and I've seen this:
Decide if you need a content provider.
You need to build a content
provider if you want to provide one or more of the following features:
You want to offer complex data or files to other applications.
You want to allow users to copy complex data from your app into other
apps.
You want to provide custom search suggestions using the search
framework.
You don't need a provider to use an SQLite database if the
use is entirely within your own application.
I'm developing an app that syncs data on background when the position changes through an IntentService.
What I've seen is that with ContentProvider you could observe when data changes which I really want without user noticing it. It changes in IntentService and MainActivity observes this changes and when it's notificated, layout content change
Is it a great idea to use a ContentProvider although they don't even mention this?
Thanks
Personally, I have been using ContentProviders in all my projects for the last year and a half. They provide good, database independent, data abstraction to access your data. They are very flexible, I even had a play project where one URI pointed to a SharedPreference while all others where for accessing database tables. ContentProviders also allow you to use already built framework infrastructure such as CursorLoaders, for example. Implementing your own from interfaces and abstract classes is not that hard, but it may be time consuming and error prone, being able to just leverage work that's already been tried and tested is a great advantage.
By the way, I remember the same exact question on a post in google+ about 2 weeks ago where Cyril Mottier gave a very good answer. You can read it here.
I write an Android app and asking myself how to manage cursors. I know how to get data through a cursor back from the database. I don’t want to handle the lifecycle of these cursors by myself.
For Android 2.x and below I used, according to the Android API, methods like managedQuery and startManagingCursor. These methods are now deprecated. Instead of these methods I should use the Loader class for example (CursorLoader). As far as I know CursorLoader must be backed by a ContentProvider. The Android SDK recommends ContentProvider only if I want to share my data. But I just want to write a simple app, where no data should be shared.
In all my research I just find tutorials about Loaders in combination with ContentProvider. The SDK says that I can also write my own Loader over the class AsyncTaskLoader. Does someone already have some experience how to implement such a Loader? Are there any best practices? Are there any good tuturials how to implement such a Loader?
Or is it just better to implement a ContentProvider, so I can use the CursorLoader (this means a lot of work for just having a managed cursor)?
To make the ContentProvider private use android:exported="false" in your manifest.
ContentProviders are easier than you think and are the suggested way by the Android team. See http://responsiveandroid.com/2012/03/19/using-an-android-cursor-loader-with-a-content-provider.html for a good example of creating a ContentProvider.
How can two processes in an Application, one an Activity and another a Service can use a common SQLite Database? This is not a question targeting very specific problem, but I looking for a solution from last three but no help.
Thanks for help.
You can write a ContentProvider which will do all the work with SQLite and both applications will use it to access DB.
http://developer.android.com/guide/topics/providers/content-providers.html
I have a few questions regarding sql server in android.
Essentially, I am tring to create an app that communicates to a SQL server, runs queries, creates new tables, rows, etc. I have been doing a lot of research recently about getting a connection to a SQL server in android. I've seen the tutorial on using a php file and it seems that isn't quite what I am looking for.
My questions:
Is it possible to create an app like the one I described above?
Do I need to do it using a php file? (like the tutorials)
Is there another way to do what I am looking to do?
Should I create a webservice to do the database portion of it? If so, are there any tutorials out there about that?
I apologize for my noob-y questions. Thanks for your help
You should definitely create a webservice, because otherwise any malicious user who has access to your app (downloads it) could easily trash your DB. But allowing insertion and creation privileges to users seems like a bad idea already.
If your users need a personal db, why don't you use sqlite which is stored locally and has no access delays, and no internet connection requirements? Why do you want a single db that is completely exposed to everyone?
It is not a good idea to communicate directly to SQL server from Android Phones. You might hit so many technical constraints when you keep going with the development. I am not sure about he end result as well. It would be great to go ahead with the service that way you might have lot of controls inside the application and design it efficiently... Just a thoughts :)