I'm using content provider to manage my application data, which is not shared with other applications. However, there is some boilerplate code such as translating the cursor to domain object. ORMLite provides a more elegant way that mapping the database entry to domain object directly. So I want to replace the content provider with ORMlite. But I have some worry:
whether I should replace the content provider with ORMLite ?
I do not think, you can compare with an ORM with Content Provider. ORMLite offers following features link to user and has complete separate goal when developed.
But beside the things you mention, their are couple of other benefits of content provider.
if you want to share date between multiple application or process. May be right now you do not have any plan to do so, but seems like you app is heavy on database, and in future if you plan to share your data with third party or your another app you have an option with content provider.
Content provider is standard throughout all release of Android, that also means that your app is safe with that. I am pretty sure ORMLite is stable too. But do you really wanna take that risk, specially if that not saving your time or you do not have any business requirement to do so. Android API is already fragmented do you want to take another work load on top of that?
if you wanna upload data to cloud it is easy to integrate with SyncAdapter
Use android security and permission feature.
You are right about the extra code needed to process Content Provider.
Right now i am working on a project we have around 20 tables. I have created a DAO for every tables. Which basically internally uses Content provider.
DAO->Content Provider->SQL Lite Open Helper
Class XyzDao{
private final Context mContext;
XyzDao(Context context){
this.mContext=context;
}
public String getMyData(){
//content provider code
return myData;
}
public void setMyData(String x, int y, double z){
//content provider code to set the data
}
}
I could have done without Content Provider and right now with current requirement that would worked fine but still i choose this route. You will ask probably why?
And, the best part is from any Activity i can simply use my DAO to access database.
Alternatively you can directly access SQLLiteOpenHelper from your DAO.
At the end of the day every choice depend on your business requirement. If you have lots of persistence objects ORMLite could be a good choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With