SlideShare a Scribd company logo
2
Most read
3
Most read
4
Most read
Android Local
Databases
By Muzamil Nawaz
Data Storage
on Android
• Androidprovides several optionsfor you to save
your app data.
• The solutionyou choose dependson your specific
needs, such as how much space your datarequires,
what kind of data you need to store.
• Different data storage optionsavailableon
Android:
Internal file storage:Store app-privatefiles on the
device file system.
External file storage: Store files on the shared external
file system. Thisis usuallyfor shared user files,
such as photos.
Shared preferences: Store privateprimitive data in key-
value pairs.
Databases : Store structured datain a private
database.
• Except for some types of files on external storage,
all these optionsare intended for app-privatedata,
the data is not naturallyaccessible to other apps.
Why SqLite?
SQLite Database for Data Storage and Retrieval
SQLite is very lightweight, open source, relational database that comes with Android OS.
In Android, integrating SQLite is a tedious task as it needs writing lot of boilerplate code
to store simple data.
Consider SQLite when your app needs to store simple and structured data objects.
Alternatively, Room Persistence Library could be used for better APIs and easier
integration.
SQLite
Challenges
Boilerplate code to convert
SQL queriestoJavaData
objects
Database operationsonthe
main thread
Unmaintainable code - As your
schemachangesyouneedto
update the affectedSQL
queriesmanually.
SQL queriescheckedat
runtime (Nocompile time
verificationof SQLqueries)
Untestable code
Room
Persistence
Library (RPL)
Solution for the
above
challenges
Room Persistence Library (RPL)
• Room is an abstraction on top of SQLite database. It's part of the
Architecture Components by Google.
• Room enables you to easily work SQLite databases in Android.
• The Room persistence library acts as a layer that abstracts raw SQLite
and lets you make use of robust database access while keep you close to
SQLite so it doesn't get in the way when you want to access low level
features of SQLite.
Components of Room Library
Components of Room
Library
There are 3 major components in Room:
• Database : Contains the database holder and
serves as the main access point for the underlying
connection to your app's persisted, relational data.
• Entity: Represents a table within the database.
• DAO: Contains the methods used for accessing the
database.
Working of RPL
Steps for making an app that uses
SQLite Database to store data
• Add Dependencies
• Add Room Entities
• Add DAO Class
• Build Database
Important Note
to remember
Add Dependecies
• Open the application level build.gradle file and add
the dependencies for Room:
Implementation "android.arch.persistence.room:runt
ime:1.1.0"
AnnotationProcessor "android.arch.persistence.room
:compiler:1.1.0"
testImplementation "android.arch.persistence.room:
testing:1.1.0"
Adding Room Entities
Important
annotations
• @Entity – by using this annotation, Room
will know that this class will be a table in the
database and the table name will define the
name of the table
• @PrimaryKey – is used to set up the primary
key of the table.
• @ColumnInfo – defines the name of the
column from the table if we don’t want to
use the name of that field
• You also need to add getters and setters.
Creating DAO Class
Details about DAO
• @Dao – by using this annotation Room knows that it should provide
the implementation for our interface by generating code for the
defined methods.
• In this interface we could define the CRUD operations for our entity and
also any other operations that are necessary in order to obtain the data.
• Also Room offers us query validation at compilation time, so if we will
write incorrectly the name of a table or a field we will know if after the
code will be compiled.
Database Class
Database Class contd...
Android local databases
Android local databases
Got Any
Questions?
Please go ahead...

More Related Content

What's hot (20)

PPTX
SAP BO Web Intelligence Basics
Kiran Joy
 
PPT
Introduction to ado.net
Paneliya Prince
 
PPTX
Abap data dictionary
SmartGokul4
 
PPTX
4 Ways to Merge IBM i Data with Microsoft Excel
HelpSystems
 
PPT
Actuate BIRT - library
Aishwarya Savant
 
PPTX
Ms access 1
aliamla
 
PPT
Instant J Chem - Introduction and latest
ChemAxon
 
PPTX
Using sqlite database in android with sqlite manager browser add ons
Vincent Clyde
 
PPT
Flexible Resources In 3 6 And E4
szbra
 
PPT
Oracle reports
Lacc Corona
 
PDF
Bt0066 database management system1
Techglyphs
 
PPTX
Access essentials brionna elmore
capjjj
 
PPTX
ACS 248th Paper 108 NIST-IUPAC Solubility Data
Stuart Chalk
 
PPTX
Abap dictionary 1
venkata karthik
 
PPTX
SQLite database in android
Gourav Kumar Saini
 
PDF
Introduction to SQLite: The Most Popular Database in the World
jkreibich
 
PPTX
External Content Types WIS SPUG
arenza
 
PPT
1-informatica-training
Krishna Sujeer
 
PPTX
Database application and design
sieedah
 
PPT
App c classicadmin2
Naresh Kumar SAHU
 
SAP BO Web Intelligence Basics
Kiran Joy
 
Introduction to ado.net
Paneliya Prince
 
Abap data dictionary
SmartGokul4
 
4 Ways to Merge IBM i Data with Microsoft Excel
HelpSystems
 
Actuate BIRT - library
Aishwarya Savant
 
Ms access 1
aliamla
 
Instant J Chem - Introduction and latest
ChemAxon
 
Using sqlite database in android with sqlite manager browser add ons
Vincent Clyde
 
Flexible Resources In 3 6 And E4
szbra
 
Oracle reports
Lacc Corona
 
Bt0066 database management system1
Techglyphs
 
Access essentials brionna elmore
capjjj
 
ACS 248th Paper 108 NIST-IUPAC Solubility Data
Stuart Chalk
 
Abap dictionary 1
venkata karthik
 
SQLite database in android
Gourav Kumar Saini
 
Introduction to SQLite: The Most Popular Database in the World
jkreibich
 
External Content Types WIS SPUG
arenza
 
1-informatica-training
Krishna Sujeer
 
Database application and design
sieedah
 
App c classicadmin2
Naresh Kumar SAHU
 

Similar to Android local databases (20)

PDF
Android development beyond the basics
Vanjikumaran Sivajothy
 
PPTX
Asp .net folders and web.config
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Structured Query Language Manipulate database.ppt
Srinivas437325
 
PPTX
Storage 8
Michael Shrove
 
PPT
Android project architecture
Sourabh Sahu
 
PPTX
Asp .net folders and web.config
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Asp folders and web configurations
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Mobile application Development-UNIT-V (1).pptx
JayasimhaThummala1
 
PPTX
iOS Beginners Lesson 3
Calvin Cheng
 
PPTX
6CS027 Lecture 5 Files and Database Storage (1).pptx
kusumjeewanthi
 
PDF
Dicoding Developer Coaching #26: Android | Menyimpan Database dengan Lebih Si...
DicodingEvent
 
PDF
Android datastorage
Krazy Koder
 
PPT
D I T211 Chapter 1
askme
 
PPT
D I T211 Chapter 1 1
askme
 
PPTX
Overview of Data Base Systems Concepts and Architecture
Rubal Sagwal
 
PDF
The Best Local Database for React Native Application Development .pdf
Techugo
 
PPTX
this is PPT for mobail application development
swapnildhage339
 
PPTX
Android session 4-behestee
Hussain Behestee
 
PPTX
DBMS Bascis
Venkata Ramireddy Chirra
 
PPT
Lecture-1.ppt
ChSheraz3
 
Android development beyond the basics
Vanjikumaran Sivajothy
 
Asp .net folders and web.config
baabtra.com - No. 1 supplier of quality freshers
 
Structured Query Language Manipulate database.ppt
Srinivas437325
 
Storage 8
Michael Shrove
 
Android project architecture
Sourabh Sahu
 
Asp .net folders and web.config
baabtra.com - No. 1 supplier of quality freshers
 
Asp folders and web configurations
baabtra.com - No. 1 supplier of quality freshers
 
Mobile application Development-UNIT-V (1).pptx
JayasimhaThummala1
 
iOS Beginners Lesson 3
Calvin Cheng
 
6CS027 Lecture 5 Files and Database Storage (1).pptx
kusumjeewanthi
 
Dicoding Developer Coaching #26: Android | Menyimpan Database dengan Lebih Si...
DicodingEvent
 
Android datastorage
Krazy Koder
 
D I T211 Chapter 1
askme
 
D I T211 Chapter 1 1
askme
 
Overview of Data Base Systems Concepts and Architecture
Rubal Sagwal
 
The Best Local Database for React Native Application Development .pdf
Techugo
 
this is PPT for mobail application development
swapnildhage339
 
Android session 4-behestee
Hussain Behestee
 
Lecture-1.ppt
ChSheraz3
 
Ad

More from FatimaYousif11 (15)

PPTX
Day 2 react bootcamp
FatimaYousif11
 
PPTX
The concept of vector art
FatimaYousif11
 
PPTX
CV/resume writing
FatimaYousif11
 
PPTX
Day 8 sketchware
FatimaYousif11
 
PPT
Firebase
FatimaYousif11
 
PPTX
Day 5 android app code advancement
FatimaYousif11
 
PPTX
Day 4 android bootcamp
FatimaYousif11
 
PPTX
Android app code mediator
FatimaYousif11
 
PPTX
Android App code starter
FatimaYousif11
 
PPTX
Android bootcamp-day1
FatimaYousif11
 
PPTX
Getting started with android development
FatimaYousif11
 
PPTX
Hello to Kotlin
FatimaYousif11
 
PPTX
Hacktoberfest slides
FatimaYousif11
 
PPTX
Info session about dsc
FatimaYousif11
 
Day 2 react bootcamp
FatimaYousif11
 
The concept of vector art
FatimaYousif11
 
CV/resume writing
FatimaYousif11
 
Day 8 sketchware
FatimaYousif11
 
Firebase
FatimaYousif11
 
Day 5 android app code advancement
FatimaYousif11
 
Day 4 android bootcamp
FatimaYousif11
 
Android app code mediator
FatimaYousif11
 
Android App code starter
FatimaYousif11
 
Android bootcamp-day1
FatimaYousif11
 
Getting started with android development
FatimaYousif11
 
Hello to Kotlin
FatimaYousif11
 
Hacktoberfest slides
FatimaYousif11
 
Info session about dsc
FatimaYousif11
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 

Android local databases

  • 2. Data Storage on Android • Androidprovides several optionsfor you to save your app data. • The solutionyou choose dependson your specific needs, such as how much space your datarequires, what kind of data you need to store. • Different data storage optionsavailableon Android: Internal file storage:Store app-privatefiles on the device file system. External file storage: Store files on the shared external file system. Thisis usuallyfor shared user files, such as photos. Shared preferences: Store privateprimitive data in key- value pairs. Databases : Store structured datain a private database. • Except for some types of files on external storage, all these optionsare intended for app-privatedata, the data is not naturallyaccessible to other apps.
  • 4. SQLite Database for Data Storage and Retrieval SQLite is very lightweight, open source, relational database that comes with Android OS. In Android, integrating SQLite is a tedious task as it needs writing lot of boilerplate code to store simple data. Consider SQLite when your app needs to store simple and structured data objects. Alternatively, Room Persistence Library could be used for better APIs and easier integration.
  • 5. SQLite Challenges Boilerplate code to convert SQL queriestoJavaData objects Database operationsonthe main thread Unmaintainable code - As your schemachangesyouneedto update the affectedSQL queriesmanually. SQL queriescheckedat runtime (Nocompile time verificationof SQLqueries) Untestable code
  • 7. Room Persistence Library (RPL) • Room is an abstraction on top of SQLite database. It's part of the Architecture Components by Google. • Room enables you to easily work SQLite databases in Android. • The Room persistence library acts as a layer that abstracts raw SQLite and lets you make use of robust database access while keep you close to SQLite so it doesn't get in the way when you want to access low level features of SQLite.
  • 9. Components of Room Library There are 3 major components in Room: • Database : Contains the database holder and serves as the main access point for the underlying connection to your app's persisted, relational data. • Entity: Represents a table within the database. • DAO: Contains the methods used for accessing the database.
  • 11. Steps for making an app that uses SQLite Database to store data • Add Dependencies • Add Room Entities • Add DAO Class • Build Database
  • 13. Add Dependecies • Open the application level build.gradle file and add the dependencies for Room: Implementation "android.arch.persistence.room:runt ime:1.1.0" AnnotationProcessor "android.arch.persistence.room :compiler:1.1.0" testImplementation "android.arch.persistence.room: testing:1.1.0"
  • 15. Important annotations • @Entity – by using this annotation, Room will know that this class will be a table in the database and the table name will define the name of the table • @PrimaryKey – is used to set up the primary key of the table. • @ColumnInfo – defines the name of the column from the table if we don’t want to use the name of that field • You also need to add getters and setters.
  • 17. Details about DAO • @Dao – by using this annotation Room knows that it should provide the implementation for our interface by generating code for the defined methods. • In this interface we could define the CRUD operations for our entity and also any other operations that are necessary in order to obtain the data. • Also Room offers us query validation at compilation time, so if we will write incorrectly the name of a table or a field we will know if after the code will be compiled.