Being able to save data locally  is one of the most important feature of an app. In this tutorial, I’m going to teach you how to do that by using Android SQLite Database. I’ll also teach you how to apply basic material design in your application.

Android SQLite

Android comes in with a built in local database implementation (SQLite) that stores data to a text file on a device. It supports all the relational database features and has methods to create, delete, execute SQL commands, and perform other common database management tasks. You can read more about SQLite here: SQLite Link

Steps to use SQLite in Android

  1. Create an Adapter class.
  2. Create an inner private class that extends SQLiteOpenHelper.
  3. Create a class constructor.
  4. Create an inner class constructor.
  5. Override onCreate() and onUpgrade() methods of the inner class.
  6. Create a method that will open your database.
  7. Create you database operations(Delete, Update, Select, Insert).

 

What is material design?

Material design is a comprehensive guide for visual, motion, and interaction design across platforms and devices. Android provides the following elements for you to build material design apps such as a new theme, new widgets, custom shadows and animations and many more. You can read more about material design in the official developer site of Android. Material Design Link

Now we’re going to learn both by creating a registration app using SQLite and material design. The final output of this tutorial will look like this.

In order to add material design in you Android project, first we need to add this in your build.gradle dependencies. Make sure that the version of your design library is the same as the version of your appcompat library.

Sync your build.gradle and wait for a while for this will take time downloading the library from the repository depending on the speed of your internet connection. For the SQLite, we don’t need to add it in our dependencies since it’s already a built in feature of Android.

Now create a new class in your main package folder and name it MyDBAdapter.java. This will serve as the adapter of our SQLite as what we have discussed earlier.

 

Open MyDBAdapter.java the copy and paste the codes provided below. I’ve put some comments so you’ll understand the codes.

 

Now open activity_main.xml and add the codes below. This will furnish the layout of our final output.

 

Then open MainActivity.java and add the codes provided below. Again, I’ve put some comments so you’ll understand the codes below.

 

That’s it! Fast and easy. Now you can run and test you app if it is working. The final output of this tutorial should be like this.

Now fill out all the edit text and click sign up. With the help of SQLite database, even you closed the app completely the information of the registrants will remain in your application.

If you’re having trouble reaching up to this point, then you can download the full source code here: Download Link