Android ContentProvider vs SqlLite Databases

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Android ContentProvider vs SqlLite Databases

Postby Scionwest » Mon Jan 28, 2008 2:47 am

The statement below was copied from an android tutorial on google's android page.
Typically you would implement this using a ContentProvider, and in fact the full Notepad application included with the SDK (in the samples/ directory) does implement such a ContentProvider. However, there is no reason you can't just use your own SQLite database directly as we do here


My question is, what is the differences between using the built in contentprovider and using a sqllite database? If I use a content provider, can I move my data from phone to phone, like I could if i had a sqllite db?

thanks for shedding some light on the subject!
Scionwest
Freshman
Freshman
 
Posts: 5
Joined: Tue Dec 25, 2007 6:04 am

Top

Postby plusminus » Mon Jan 28, 2008 3:42 pm

Hello Scionwest,

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.

Moving data from phone to phone is probably a bit easier if you use a SQLiteDatabase.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Scionwest » Mon Jan 28, 2008 11:34 pm

Thanks! Something else I was curious about, is the contacts info something already setup by Android in it's content provider? or will I need to create the information myself in a fresh installation of Android?
Scionwest
Freshman
Freshman
 
Posts: 5
Joined: Tue Dec 25, 2007 6:04 am

Postby plusminus » Tue Jan 29, 2008 12:59 am

Hello scionwest,

Contactlist is empty on emulator-default.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Ishtar » Tue Jan 29, 2008 10:16 am

plusminus wrote:Moving data from phone to phone is probably a bit easier if you use a SQLiteDatabase.


I disagree.. Lets say you make an app to send 'notes' (like in the notepad tut) around. Someday you then plan to update the sqldatabase, like you add another field in your table. Two different phones using two different tables will be hard to synchronise. However having a contentprovider, its rather easy: ignore fields that you don't know and fill in missing fields. Do-able with projections. Hard with sql queries. Besides, writing a simple contentprovider isn't that hard.. Copy&paste the notepad contentprovider and change every String you find. :wink:

Ishtar
Ishtar
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Wed Jan 16, 2008 10:22 pm
Location: Netherlands

Postby plusminus » Tue Jan 29, 2008 10:31 am

Hello Ishtar,

I was thinking of the 'manual' copying of the database-file to another phone.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby Ishtar » Tue Jan 29, 2008 10:35 am

Ah, i see. But that doesn't really make a difference :?:, with a content provider you can still copy the database file around. But sure, its save you time not writing a content provider

Ishtar
Ishtar
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Wed Jan 16, 2008 10:22 pm
Location: Netherlands

Postby Skeniver » Tue Oct 13, 2009 9:51 am

Hey there

I am trying to access the database in my free version of the app from the paid for version. So that when/if a user upgrades, they won't lose their data.

Is a ContentProvider the best way to do this (it will only need to be done once, so I don't really need to 'share' the data)? Or is there a better more efficient way of copy a database?

Any help on this is most appreciated!

Thanks,
Neil
User avatar
Skeniver
Senior Developer
Senior Developer
 
Posts: 106
Joined: Tue Feb 03, 2009 3:51 pm
Location: Canterbury, UK

Postby padde » Tue Oct 13, 2009 10:09 am

There is a way around that which applies to your case.
Read http://developer.android.com/guide/topics/security/security.html .. i just ran over it but i think by signing the non paid and the paid app with the same signature and with appropriate use of the "sharedUserId" tag in the manifest you can achieve exactly what you are looking for.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby Skeniver » Tue Oct 13, 2009 11:52 am

I have managed to get a connection to the 'lite' database.

http://www.anddev.org/viewtopic.php?p=27932#27932

But am now stuck on migrating the data over? Any ideas?
User avatar
Skeniver
Senior Developer
Senior Developer
 
Posts: 106
Joined: Tue Feb 03, 2009 3:51 pm
Location: Canterbury, UK

Top

Return to General

Who is online

Users browsing this forum: No registered users and 5 guests