5 Most popular Android ORM frameworks

Source: Internet
Author: User

There are several ways to save data when developing Android apps,

One is saved locally, one is in the background (API interface is provided), and the other is on an open cloud service (such as SyncAdapter would be a good choice).

For the first way, local data storage, such as embedded SQLite, you can choose to use SQL statements, Content Provider, or ORM (object Relational data mapping) directly.

The development of Android apps is primarily the Java language, so some of the ORM for the Java language can be ported to the Android platform.

The following is a general introduction to the 5 available ORM:

1. Ormlite

Ormlite is not a dedicated ORM framework for the Android platform, it is a Java ORM. Supports JDBC connection, spring and Android platform. Annotations (Annotation) are widely used in the syntax.

Official website: http://ormlite.com/sqlite_java_android_orm.shtml

2. Sugarorm

Sugarorm is a dedicated ORM for the Android platform. Provide easy-to-learn APIs. It is easy to process 1 pairs of 1 and 1-to-many relational data and simplify CRUD basic operations with 3 functions, save (), delete (), and find () (or FindByID ()).

To enable Sugarorm, you need to add the following meta-data tags in your application's androidmanifest.xml configuration:

<meta-data android:name= "DATABASE" android:value= "my_database.db"/><meta-data android:name= "VERSION" Android:value= "1"/><meta-data android:name= "Query_log" android:value= "true"/><meta-data android:name= "Domain_package_name" android:value= "Com.my-domain"/>

You can then extend the data classes you need to save from Sugarorm:

public class User extends sugarrecord<user> {    String username;    String password;    int age;    @Ignore    string bio;//this'll be ignored by Sugarorm public    User () {} public    User (string username, string p Assword,int age) {        this.username = Username;        This.password = password;        This.age = age;    }}

To add a user, the code is as follows:

User JohnDoe = New User (GetContext (), "John.doe", "secret", +); Johndoe.save (); Stores the new user into the database

Official website: http://satyan.github.io/sugar/getting-started.html

3. Greendao

When performance is important (data access is frequent), Greendao is a quick solution that can support thousands of records of crud per second, and Ormlite is almost 4.5 times times faster than Greendao. (Please benchmark the exact data).

Greendao is less than 100KB, so it has little effect on the size of the app apk.

Here's a tutorial that shows how to use Android Studio to use the Greendao framework in Android apps.

Official website: http://greendao-orm.com/

4. Active Android

Active Record (Active Directory) is a typical way of naming ORM implementations in frameworks such as Yii, rails, and so on. Active Android helps you manipulate SQLite in an object-oriented way.
To include active Android in your project, you need to add a jar file under the project's/libs directory. You can get the source code from GitHub and edit it using Maven. Then you should add these meta-data to your application's Androidmanifest.xml configuration:

<meta-data android:name= "Aa_db_name" android:value= "my_database.db"/><meta-data android:name= "AA_DB_ VERSION "android:value=" 1 "/>

Then call the Activeandroid.initialize () method in your activity:

public class MyActivity extends Activity {    @Override public    void OnCreate (Bundle savedinstancestate) {        Super.oncreate (savedinstancestate);        Activeandroid.initialize (this);        Rest of the app    }}

Now you can use Java annotations to create a model class:

@Table (name = "User") public class User extends Model {    @Column (name = "username") public    String username;    @Column (name = "password") public    String password;    Public User () {        super ();    }    Public User (String username,string password) {        super ();        This.username = Username;        This.password = password;    }}

Official website: http://www.activeandroid.com/

5. Realm

Realm is a ready-to-use Android ORM that is written in C + + and runs directly on your device hardware (no need to be interpreted), so it runs quickly. It is also open source cross-platform, iOS code can be found on GitHub, you can also find objective-c and swift written realm usages.

Official website: http://realm.io/

5 Most popular Android ORM frameworks

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.