MCCExp 7 TH
MCCExp 7 TH
Android GUI
Aim: Develop an application that makes use of database.
Theory:
Android Studio is the official integrated development environment (IDE) for Android
application development. It is based on the IntelliJ IDEA, a Java integrated development
environment for software, and incorporates its code editing and developer tools.
Android SQLite is a very lightweight database which comes with Android OS.SQLite is a
opensource SQL database that stores data to a text file on a device. Android comes in with
built in SQLite database implementation.
SQLite supports all the relational database features. In order to access this database, you
don't need to establish any kind of connections for it like JDBC,ODBC e.t.c
1. When the application runs the first time – At this point, we do not yet have a database. So
we will have to create the tables, indexes, starter data, and so on.
2. When the application is upgraded to a newer schema – Our database will still be on the old
schema from the older edition of the app. We will have option to alter the database schema
to match the needs of the rest of the app.
SQLiteOpenHelper wraps up these logic to create and upgrade a database as per our
specifications. For that we’ll need to create a custom subclass of SQLiteOpenHelpe
implementing at least the following three methods.
1. Constructor : This takes the Context (e.g., an Activity), the name of the database, an
optional cursor factory (we’ll discuss this later), and an integer representing the version of
the database schema you are using (typically starting from 1 and increment later)
Public DatabaseHelper(Context context){
Super(context,DB_NAME,null,DB_version);
}
2. onCreate(SQLiteDatabase db) : It’s called when there is no database and the app needs one.
It passes us a SQLiteOpenDatabase object, pointing to a newly-created database, that we
can populate with tables and initial data.
3. onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) : It’s called when the schema
version we need does not match the schema version of the database, It passes us
a SQLiteDatabase object and the old and new version numbers. Hence we can figure out the
best way to convert the database from the old schema to the new one.
We define a DBManager class to perform all database CRUD(Create, Read, Update and
Delete) operations.
Conclusion: We have implemented an application that makes login application that uses of
SQLite database