Skip to content

mitmel/SimpleContentProvider

Repository files navigation

Simple Content Provider

This library aims to make creation of private and public ContentProviders trivial.

If your app is backed by a database, chances are you took one look at the Content Provider API and decided that it wasn't worth the effort to use. This library aims to help that by removing the need to do all the legwork of writing all the basic CRUD operations that you'll encounter writing a basic content provider.

By using this library, you shouldn't need to write any SQL for most applications — table creation, query generation, etc. are all handled for you.

This library is loosely inspired by Django and follows some of its design principles. It also follows the RESTful design principles that underly Android's data-driven activity flow and encourages the use of URIs to represent all data objects.

One can think of this library a bit like a super stripped down ORM — similar to Hibernate or ORMlite.

Unlike ORMs, this library aims to have very little object creation in order to minimize garbage collection churn. This follows Android's existing Content Provider APIs closely, making it so that there should be very little difference between the use of the content providers created by this library and any other Content Provider Android already exposes (contacts, media, calendars, etc.).

Additionally, this library aims to be flexible enough to allow for easy extension if what it provides is too simple for your application.

Features

  • Drastically simplifies the creation of SQLite-backed ContentProviders — Android's core data persistence layer — for most common cases
  • Supports basic table/object creation as well as foreign key and m2m relationships
  • URI-based automatic query generation makes it easy to pass views of data between activities
  • Provides easy integration into Android's global search
  • Multi-process, multi-threading access is handled automatically
  • Designed to be used alongside other libraries
  • ContentProviders made with this library can be exported to other Android apps

Example

For an example / demo of the library, please see the example code (also available on Google Play). The example shows the core features as well as demonstrates how to hook the library into a UI.

It's probably best to start at SampleProvider and eventually make your way through Message and the accompanying activities.

Using

The Javadocs try to be extensive. You should start at SimpleContentProvider which includes a brief walk-through of the system.

License

Android Simple Content Provider
Copyright (C) 2011-2013 MIT Mobile Experience Lab

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software gnu.org/licenses/lgpl.html