1

I have created my own Sqlite database with all the columns that are there in Content Provider Media Image.

Now I want to save(add) all the rows (data) of Content Provider to my sqlite database.

So please help me as to which is the best memory effective and fastest way to do this.

I want to run this process in background using a service class.

Edit:-

Androids Content Provider Media/External/Image/Media Database Columns:-

_id , _data, _size, _display-name , etc.....

My presentation Layer to Display:-

_data, _size, _display-name , _custom-column

Custome Column I get after processing _data of each image, and this process is a bit time taking. So I want to do that in background and save it (mapping _custom-column with _id) so that whenever the application is launched I just present it to user.

Ankesh kumar Jaisansaria
  • 1,563
  • 4
  • 26
  • 44
  • 1
    "Now I want to save(add) all the rows (data) of Content Provider to my sqlite database." -- why? Your database will be perpetually out of date with respect to what `MediaStore` indexes. Why do you think that duplicating this data is something that the user will want you to do? – CommonsWare Apr 30 '16 at 17:03
  • @CommonsWare Thats What, I also want to update my Sqlite database every time the Content Provider MediaStore Image gets updated – Ankesh kumar Jaisansaria Apr 30 '16 at 17:05
  • 1
    Why do you think that duplicating this data is something that the user will want you to do? – CommonsWare Apr 30 '16 at 17:06
  • 1
    @CommonsWare Actually I have one more additional column attached to my database apart from those in content provider database, which is why i want to replica content provider data. – Ankesh kumar Jaisansaria Apr 30 '16 at 17:11
  • 1
    use a `CursorWrapper` in your `ContentProvider#query` method then, that way you can add some your custom columns to the "original" `Cursor` – pskink Apr 30 '16 at 17:13
  • That is akin to saying that you want to download all of Wikipedia in order to be able to link to a single Wikipedia page. For the handful of files for which you have this additional data, store that little bit of data in your own app. Then, as pskink suggests, blend the two data stores as needed (e.g., for presentation in your UI). – CommonsWare Apr 30 '16 at 17:14
  • @CommonsWare Please see the edit I have made to my question and please help me. I am really stuck at this. I think I am not able to explain my issue. Thanks for giving time. – Ankesh kumar Jaisansaria Apr 30 '16 at 17:28
  • @pskink Please go through my edited question and tell if your previous answer is application or not. Thanks – Ankesh kumar Jaisansaria Apr 30 '16 at 17:28
  • why you don't save just `_id`, `_custom-column` in your application, every time you need data get that from media database ? – Shayan Pourvatan Apr 30 '16 at 17:30
  • So everytime the new image is added in content provider database, I need to update my custome_column. Thats why I want to create a sqlite database with two columns _id and _custom-column. But now my question is how to add all _id rows from content provider to my database – Ankesh kumar Jaisansaria Apr 30 '16 at 17:33
  • Contentresolver is what you use to access content provider. The contentprovider is like a wrapper for sqlite database to deal with dataset change events ie synchronization, thread safety like not blocking ui thread, stopping a query on something as simple as orientation change. If you have a content provider you do not need a separate service its automatically in background but you do for the sqlite database. Why do you need both? add the extra column to the content provider. – Pomagranite Apr 30 '16 at 17:35
  • @user3535611 I donot have my own content provider. I am talking about androids media image content provider – Ankesh kumar Jaisansaria Apr 30 '16 at 17:36
  • 1
    and if you dont want to use a `CursorWrapper` you can still use `Cursor#setExtras` / `Cursor#getExtras` methods – pskink May 02 '16 at 06:28
  • @pskink I don't know about CursorWrapper. Can I use CursorWrapper to merge my custom-column with Androids Content Provider table, or For what do I use it? – Ankesh kumar Jaisansaria May 02 '16 at 06:32
  • `The primary use for this class is to extend a cursor while overriding only a subset of its methods.`, so you can override for example: `getColumnCount()` and / or similar methods – pskink May 02 '16 at 06:35

0 Answers0