Questions tagged [android-contentprovider]

Content providers are one of the primary building blocks of Android applications, providing content to applications.

Content providers are one of the primary building blocks of Android applications, providing content to applications. They encapsulate data and provide it to applications through the single ContentResolver interface. A content provider is only required if you need to share data between multiple applications.

For example, the contacts data is used by multiple applications and must be stored in a content provider. If you don't need to share data amongst multiple applications you can use a database directly via SQLiteDatabase

For more information about using content providers, read the Content Provider's documentation.

3206 questions
17
votes
2 answers

android content provider AUTHORITIES

What is the reason for content provider authorities? How/why do I want to use them other than I HAVE to declare them in the manifest? I've tried to do my homework on this question and cannot find a decent, cohesive discussion on this topic. Here…
JDOaktown
  • 4,262
  • 7
  • 37
  • 52
17
votes
3 answers

Android: access SQLite database via Content Provider or implement DAO?

I'm wondering which is the best approach to access my application database: use a Content Provider, or implement my DAO by hand? From my latest investigations, seems that Content Provider, even for app internal use, is preferable, but I don't know…
user1135437
  • 303
  • 1
  • 2
  • 8
17
votes
1 answer

How to address multiple content providers?

I created two content providers that work on two different tables of the same SQLite database. They share a single instance of SQLiteOpenHelper as described in the post of Ali Serghini. Each content provider is registered in AndroidManifest.xml as…
JJD
  • 50,076
  • 60
  • 203
  • 339
17
votes
2 answers

Android - Having Provider authority in the app project

An android library project contains a few providers whose authority is defined like the following in a contract class : public static final String CONTENT_AUTHORITY = "my.com.library.providers.tester"; private static final Uri BASE_CONTENT_URI =…
500865
  • 6,920
  • 7
  • 44
  • 87
17
votes
5 answers

Content Observer onChange method called twice after 1 change in cursor

I have an app in which I am hoping to send details in the android contact list to a remote server, so that the user can see his contacts online. To do this I want to notify the remote server of any changes made on the phone to the contacts list. I…
Kevin Bradshaw
  • 6,327
  • 13
  • 55
  • 78
16
votes
2 answers

When should I call close() on SQLiteOpenHelper used by ContentProvider

In my android app, I use SQLiteOpenHelper to implements ContentProvider. Query, add, delete operations are all through ContentProvider. But in one of my android phone(htc g13), I found *.db-wal file in directory /data/data/[package name]/databases.…
cmoaciopm
  • 2,076
  • 2
  • 22
  • 30
16
votes
1 answer

SQLiteConstraintException: error code 19: constraint failed -- Android error

I have seen some other questions about this, but none of the answers really seemed to work for my code. I'm getting a 'SQLiteConstraintException: error code 19: constraint failed' error when I try to insert into my DB. Here is the code for the…
Rebecca
  • 163
  • 1
  • 1
  • 4
16
votes
3 answers

how to decide between direct database access and content provider?

I am writing an application that consists of business logic and UI parts. There is quite big amount of data to be stored and accessed/modified by both BL and UI. In most of the cases changes to the stored data should be reflected by UI immediately.…
Asahi
  • 13,378
  • 12
  • 67
  • 87
16
votes
2 answers

Android ContentProvider and Google IO Rest Talk

To all, If you watch the Google IO session on building Android REST apps they are suggesting in all three design patterns to use Content Providers regardless if you need to share data or not. If you look at the Content Provider class doc at…
Koppo
  • 591
  • 4
  • 15
16
votes
2 answers

When ContentResolver.notifyChange() is called for a given URI, are ContentObservers observing descendent URIs of this URI notified?

A hopefully straightforward question: When ContentResolver.notifyChange() is called for a given URI, are ContentObservers observing descendent URIs of this URI notified? E.g. Say I have a cursor setup to observer the URI of a specific resource: Uri…
16
votes
3 answers

Good way to cache data during Android application lifecycle?

keeping my question short, I have created an application with 3 activities, where A - list of categories, B - list of items, C - single item. Data displayed in B and C is parsed from online XML. But, if I go through A -> B1 -> C, then back to A and…
sniurkst
  • 7,212
  • 5
  • 30
  • 30
16
votes
1 answer

Grant uri permission to uri in EXTRA_STREAM in intent

With FLAG_GRANT_READ_URI_PERMISSION in intent that passed to startActivity, we can grant Uri permission if the uri is set using setData. But if the Uri in put in EXTRA_STREAM, the Uri is not granted before jeallybean. I know we can use…
Bear
  • 5,138
  • 5
  • 50
  • 80
15
votes
2 answers

Why/Should we implement BaseColumns when using a Content Provider in Android?

I was browsing the source code for Google IOSched App and noticed the following code snippet as part of their Content Provider implementation: public static class Blocks implements BlocksColumns, BaseColumns. As far as I know BaseColumns is simply…
Mandel
  • 2,968
  • 2
  • 22
  • 19
15
votes
1 answer

Android - Using Dao Pattern with contentProvider

Is correct to use ContentProvider with dao Pattern. ? or it will bring any performance issue ? I will try to explain. I've a contentProvider. an activity, a dao and a bean .. this is the code : class Bean(){ String name; } class Dao{ …
antonio Musella
  • 534
  • 1
  • 7
  • 20
15
votes
1 answer

Provide the caller id for incoming call from my own app

I want to write an App that can identify the phone number of incoming (unknown) calls by looking into a table inside my app (e.g. an SQLite Database Table). I already implemented this in iOS using a Call Directory Extension, but for Android the only…