Top Banner
Android SQLite Database
25

Database

Jun 23, 2015

Download

Education

National Mobile Application Awareness Development & Capacity Building Program
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Database

AndroidSQLite Database

Page 2: Database

WHY DATABASES ON ANDROID?Common usage for a database

• Huge amounts of data

• Convenient query language to obtain data

• Accessed/modified by huge amount of users Applications:

• backend for multi-tier web architecture,• backend for business process architectures like SAP• areas: banks, insurance companies, ...

Android • Small scale architecture, little data, few applications ...

Page 3: Database

What is SQLite?• SQLite is Open Source Database embedded into

Mobile Devices.

• SQLite supports SQL syntax, transactions and

prepared statements.

• SQLite consumes low memory approx. 250Kbyte.

Page 4: Database

SQLite• Relational database with tables (DB schema)

• Popular embedded database, here: integrated in Android

• SQL interface + small memory footprint + decent speed

• Native API not JDBC

• Properties (from http://www.sqlite.org/different.html)• Zero configuration and serverless• Single database file & stable across platforms• Compact, public domain, readable source code• Manifest typing and variable length records

Page 5: Database

SQLite vs Content Provider• SQLite

• Persistent storage of data• Data accessible to a single application (the owner)• Often wrapped by a Content Provider

• Content Provider• Specialized type of data store to share data across apps• Exposes standardized ways to retrieve/manipulate data• Query with URI: <standard_prefix>://<authority>/<data_path>/<id>• Examples: content://browser/bookmarks, content://contacts/people

• Built in

Page 6: Database
Page 7: Database

Make a demo project

Page 8: Database
Page 9: Database

Create Database

Add that CREATE_TABLE_SQL into onCreate Method

Page 10: Database

Database Open/Close

Page 11: Database

Database Insert()

Page 12: Database

Now in Main Activity

Page 13: Database

Add Button Click

Page 14: Database

Output

Page 15: Database

Now Get Data From Database

Page 16: Database

Add a Layout to Show Data in List

Page 17: Database

Add another Layout for List Rowlistrow.xml

Page 18: Database

Add New ContactListActivity

Page 19: Database

Add Button Click On MainActivity

Add another button name Show All Contact in our activity_main.xml with id:btnAllContact

Page 20: Database

Add getContacts() in DatabaseAdapter Class

This method will return data from database in a Arraylist.

Page 21: Database
Page 22: Database

Make a Custom Adepter

As you have done before in ListView Session

Create a CustomAdapter to bind data in list adapter.

Then set the adapter in our listview.

Page 23: Database
Page 24: Database

Now back in our ContactListActivity

Page 25: Database

Output