database
DESCRIPTION
National Mobile Application Awareness Development & Capacity Building ProgramTRANSCRIPT
![Page 1: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/1.jpg)
AndroidSQLite Database
![Page 2: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/2.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/3.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/4.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/5.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/6.jpg)
![Page 7: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/7.jpg)
Make a demo project
![Page 8: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/8.jpg)
![Page 9: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/9.jpg)
Create Database
Add that CREATE_TABLE_SQL into onCreate Method
![Page 10: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/10.jpg)
Database Open/Close
![Page 11: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/11.jpg)
Database Insert()
![Page 12: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/12.jpg)
Now in Main Activity
![Page 13: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/13.jpg)
Add Button Click
![Page 14: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/14.jpg)
Output
![Page 15: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/15.jpg)
Now Get Data From Database
![Page 16: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/16.jpg)
Add a Layout to Show Data in List
![Page 17: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/17.jpg)
Add another Layout for List Rowlistrow.xml
![Page 18: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/18.jpg)
Add New ContactListActivity
![Page 19: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/19.jpg)
Add Button Click On MainActivity
Add another button name Show All Contact in our activity_main.xml with id:btnAllContact
![Page 20: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/20.jpg)
Add getContacts() in DatabaseAdapter Class
This method will return data from database in a Arraylist.
![Page 21: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/21.jpg)
![Page 22: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/22.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/23.jpg)
![Page 24: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/24.jpg)
Now back in our ContactListActivity
![Page 25: Database](https://reader034.vdocument.in/reader034/viewer/2022052621/5588f857d8b42afe678b4598/html5/thumbnails/25.jpg)
Output