B
B
babaevmm2016-05-19 15:53:58
Android
babaevmm, 2016-05-19 15:53:58

Why is a ContentProvider needed in a single project?

Hello everybody!
For the life of me, I can’t understand why I need to use ContentProvider when working with data (SQLite) in an application, if I am not going to provide access to any other application?
The official Google documentation also says that it was created to provide data "outside". In my next question ( https://toster.ru/q/317954), a kind person (thanks to him again for the answer) advised me to use it too. After reading about him came to this question.
Is there really no way to organize data access without it (elegantly)? For example, do something like a repository, but only without a provider
There was advice to use ContentProvider + CursorAdapter + CursorLoader, but then it is necessary to have the "_id" field in the database, which I basically do not need if I have a GUID (UUID). Again, is there anything without it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Gamega, 2016-05-19
@babaevmm

You are looking for a unique solution, for all occasions. But this is not always the case, each task requires its own solutions.

+1
yes, if the field is not _id, then a number of native features from sdk are not available, even by clicking on the list item you will not get its key (out of the box if the pc is _id, then when you click on the list item you will get its _id)
_id is essentially already a standard for android, therefore, except for cases where, for some very important reasons, you need to name the PC somehow differently, I would still recommend calling the PC _id
Of course you can, but then you will have to cut a number of features myself
. I like the ContentProvider for its simplicity, but I don’t like it for the crooked api (no, really, the method in which almost all parameters are often null in 2016 is too much), but its api is compensated by its stability
once again I will describe the case of its use when you don’t need to give access somewhere
for clarity, imagine that we have a tablet and that the screen is divided into 2 fragments, the
first fragment is the tape of goods,
the second basket
(yes, strange ux, but what to do ....)
in on the feed, the user clicks on the add to cart button, while the ui is magically updated in the second fragment, while no complex logic needs to be implemented for this
I think the same effect can be achieved using rxjava but you have to sweat

A
Anton Agaltsov, 2016-05-19
@Archusha

Yes, it all depends on the task. And habits.
Depends on many things from the requirement to whether this code will be supported.
You can also make a repository with direct SQL queries or using a cursor. Depends on the project.
You are looking for a unique solution, for all occasions. But this is not always the case, each task requires its own solutions.
Perhaps specifically in your case, the use of a content provider is the same as setting Bitrix for a two-page business card site.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question