Android Apps : An Open Source Database

1007 Words5 Pages
Most Android apps will need to hold on user data at sometimes. If you want to store your contact information which is repeating or structured data the SQL lite is one of best option. There are different ways to store user data, but SQLite databases are a very smoothie and speedy method of saving user (or app) data and information. This class assumes that you are familiar with SQL databases in general and helps you get started with SQLite databases on Android.
In this chapter you will learn and understand how we can use SQL lite in android.
Objectives
• How to store data using SQLite database
• Querying the SQLLite database
• Working with content providers
Store data using SQLite database

What is SQLite?
SQLite is an Open Source database.
…show more content…
• DATA is the path which the Environment.getDataDirectory() method returns.
Now we shall create a project for better understanding. We shall use a table called Contacts so we can store user contacts. This table contains three columns id (INT), name (TEXT), phone_number(TEXT).
Table Name: Contacts
Field Type Key
Id INT PRI
Username TEXT
Mobile_number TEXT

Figure 1: Image of text field
Now before moving further, you need to write your Contact class with all getter and setter methods to maintain single contact as an object public class Contact { //private variables int _id; String _username; String _mobile_number; // Empty constructor public Contact(){ } // constructor public Contact(int id, String username, String _mobile_number){ this._id = id; this._name = username; this._mobile_number = _mobile_number; } // constructor public Contact(String username, String _mobile_number){ this._name = username; this._mobile_number = _mobile_number; } // getting ID public int getID(){ return this._id; } // setting id public void setID(int id){ this._id = id; } // getting username public String getuserName(){ return this._username; } // setting username public void setName(String username){ this._name = username; } // getting mobile number
Open Document