Below is how I do it with SORMA - An Android Content Provider solution.
Map your Java POJO to database table:
@Table(
name="contact",
keyColumn="id",
autoId=true,
create="create table if not exists contact ("
+ " id INTEGER primary key autoincrement"
+ ", firstName text"
+ ", lastName text"
+ ", married tinyint"
+ ")"
)
public class Contact {
private Integer id;
private String firstName;
private String lastName;
private boolean married;
......
Create content provider class:
import com.gaoshin.sorma.annotation.ContentProvider;
import com.gaoshin.sorma.annotation.SormaContentProvider;
@ContentProvider(
version = 1,
mappingClasses = {
Contact.class,
Phone.class
}
)
public class AddressBookContentProvider extends SormaContentProvider {
}
Define content provider in the AndroidManifest.xml:
Use the content provider:
sorma = SORMA.getInstance(getBaseContext(), AddressBookContentProvider.class);
// insert contact
Contact contact = new Contact();
contact.setFirstName("fname1");
contact.setLastName("lname1");
sorma.insert(contact);
Done!
(You can find more info here.)