Why should I use a ContentProvider with exported=false? - android

I can't figure out why I should use a ContentProvider with the setting "android:exported=false" in the AndroidManifest.xml. Aren't ContentProviders created to share data between multiple applications? In this way, I am restricting data sharing only to my application and not to external applications. But at this point I can simply use a database in SQLite (maybe with SQLiteOpenHelper).
In the case where I need to create a pre-populated database by loading data from a Rest API, but at the same time I do not need to share my data to other applications, should I create a ContentProvider with the setting "android:exported=false" using the ContentProviderOperation and ContentProviderOperation.Builder Classes (I have seen that these two Classes are used for massive data insertion) ? Or should I create a database in SQLite and insert the data using the INSERT command ?
Thank you!

Related

What is content provider?

I just followed tutorial in developer.android.com to create sync adapter to provider feature "synchronization between local db with server db", and after bloody trial and error i managed to make it work (onPerformSync has called successfully).
And now for next step to create sync feature, from what i have read in several articles, I need to create a content provider. I already read https://developer.android.com/guide/topics/providers/content-provider-basics.html but I still dont get it how does it work.
from this link https://developer.android.com/guide/topics/providers/content-provider-basics.html, it raised several questions in my head:
what table they are talking about? are they talking about sqlite table or some "another" table?
content://user_dictionary/words what uri is this? is this uri to table file where sqlite stored? if it's, how do I know mine? I mean where did my sqlite store table that I created?
from what I read (if i got it right), ContentProvider just like a repository. do they have same functionality? I already created my repository using anko https://gist.github.com/mockiemockiz/a552a669d28a3c90c144bc1542b86a5e , can I use that code / convert that code to be ContentProvider that able to tell sync adapter the data has changed?
I just followed tutorial in developer.android.com to create sync adapter to provider feature "synchronization between local db with server db", and after bloody trial and error i managed to make it work (onPerformSync has called successfully).
FWIW, SyncAdapter is not especially popular.
what table they are talking about?
The word "table" shows up 40 times on that page. We have no way of knowing which of those 40 concerns you, and they use the term in multiple ways.
what uri is this?
That is a Uri pointing to a collection of data ("table") in the user_dictionary ContentProvider.
is this uri to table file where sqlite stored?
That is for the developer of the ContentProvider to decide. The ContentProvider API does not stipulate where the data is stored. It could be stored in SQLite, or a JSON file, or whatever. Convention says that a collection of data exposed by a ContentProvider maps to a SQLite table or view, but that is not required.
if it's, how do I know mine?
You know it is your ContentProvider if you used user_dictionary as your authority (see android:authorities in the <provider> element in the manifest).
I mean where did my sqlite store table that I created?
That is up to you. ContentProvider has nothing to do with SQLite, unless you write code that ties a ContentProvider implementation to SQLite.
ContentProvider just like a repository
Not really, at least in terms of how I use the term "repository". A ContentProvider is a wrapper around some data storage mechanism, to allow outside parties to have controlled access to that data.
can I use that code / convert that code to be ContentProvider that able to tell sync adapter the data has changed?
That would be rather difficult. This is one of the reasons why few developers use SyncAdapter.

Android SQLite data displaying

I'm kinda new in android development and I am little confused about content providers. Content providers are used to share your data with other application legally, but is it correct to use it for retrieving your data from SQLite databaseand display it in, for instance listView? What is better solution for displaying data from db?
Thanks
Yes it is legit using the ContentProvider to retrieve data from a SQLite database while its perfectly fine creating an Handler to handle the SQLiteOpenHelper and just using it.
Its all depends on your app's needs,
Me individually for my own app if no need for sharing data wouldn't use a content provider.
if you don't need to share the data base from your app it's not necessary to use a Content Provider

How to create database using Db4o in android?

I am developing an App in which now i have to create database for more better user experience. Then i came to know about DB4o which is many times faster tool for creating database than other like SQLite, MySql etc, but the problem is i am not able to find any single example that explains about DB4o and how to create database using Db4o. If anybody has used it, please post an example or send me link.
To store the object in database use
db().store(exercise);
To retrieve All records from database, use
db().query(Object);
To retrieve particular record from database, use
db().queryByExample(Object);
If you need example, Try My blog example using db4o.
In this example, simple student object will be stored in database using db4o. Student object will contain student name, register number, and his age.
Thank you.

ContentProvider usage

A content provider is only required if you need to share data between multiple applications.
Is this the only purpose of using it? What about simply getting data from the WS and writing it in the CP and then reading from here in Activities?
What about iosched:
CP is used here to share a database for several apps?
you just can achive that with a database, but I strong recommend the use of contentprovider even if you are not going to share data between aplications. classes such as CursorLoader (correction) load directly datas from contentprovider, if you use just a database you have to extend this class to get the same performance
so to conclude it's all made for working with contentprovider.

Android ContentProviders vs SQLite

If we want to share our data with other Android applications,
(1) we may create a SQlite database and make it accessible by other applications or
(2) create a ContentProvider.
What are the basic differences in the above mentioned two approaches?
ContentProvider is exposing data to other application, a non-content provider database is only accessible by that application.

Categories

Resources