SQLite CRUD Example in Android using ActiveAndroid Library

Hello friends, today we will see a simple SQLite CRUD Example in Android using ActiveAndroid Library. I have also posted about SQLite CRUD Example in Android before. But in this post we will  do it using ActiveAndroid Library. You can check the previous tutorials about SQLite from below.

What is ActiveAndroid Library?

It is an android library which allows you to perform SQLite Database operations without writing even a single SQL statement.

The best thing of using this library for SQLite operation in your application is it will simplify the SQLite operation. You don’t need to write SQL statements. And you can perform SQLite operations very easily.

SQLite CRUD Example in Android using ActiveAndroid Library

So lets begin our tutorial of SQLite CRUD Example for Android using ActiveAndroid Library. So the first thing we need to do is create a new Android Project. And follow the below given steps.

Adding ActiveAndroid Library to your Android Project

  • In the project you just created go to the project level build.gradle file and add these two lines inside allprojects block.

  • Now come to app level build.gradle file and inside dependencies block add the following line.

  • Sync your project now and its done.

Initializing ActiveAndroid Library in Your Project

  • First add the following meta tags inside your AndroidManifest.xml (If you are getting confused then in bottom you can see the whole AndroidManifest.xml file).

  • Create a class named MyApplication to initialize ActiveAndroid library. This class will be launched on the application launch.
  • Write the following code in this class.

  • Now you have to define the above class in your AndroidManifest.xml file. To do this add the following code inside application  tag.

Creating Table Model

  • To create table using ActiveAndroid library you need to create a class that will extend the Model class. In this post I will create a small table named Inventory.
    Create a class named Inventory and write the following code.

  • If you want to add more columns just repeat the code by changing name value and variable name. You also need to define your models inside manifest. So for the above model write the following meta data inside AndroidManifest.xml. 

Performing SQLite CRUD

  • The first thing in CRUD is means create. So we need a User interface to Create a new Inventory. For this we will create a simple layout as shown below.

SQLite CRUD Example in Android

  • To make the above layout use the following xml code and paste it to your activity_main.xml file.

  • We can use the following code to save name to SQLite.

  • As you can see how simple it is. We haven’t written a single SQL Query to store to database. Now lets move to the R in CRUD, which stands for READING from database. To read from database we can use the following code.

  • By using it I have made my activity little enhanced like when you add an item to the inventory it will be displayed in the listview we created. The final code I have written is below.

  • The final AndroidManifest.xml is

  • Now run your app and you will see the following output.

SQLite CRUD Example in Android

  • Bingo! its working fine. So I am wrapping up this post here. We have done half C and R (Create and Read) in the next tutorial we will do  U and D (Update and Delete).
  • If you are having trouble you can get my source code from the link given below.

So thats all for this SQLite CRUD Example in Android friends. Leave your comments if having any confusions regarding this SQLite CRUD Example in Android Tutorial. Thank You 🙂