SlideShare a Scribd company logo
1 of 35
©W3Engineers2018
Store Data locally
12th September
©W3Engineers2018
Anjan Debnath
Sr. Software Engineer
Store data locally
Anjan Debnath
Ways to store data in Android
Store data locally
Anjan Debnath
Shared Preference
Store data locally
Anjan Debnath
SQLite
Store data locally
Anjan Debnath
File Storage
Store data locally
Anjan Debnath
Content Provider
Store data locally
Anjan Debnath
Cloud Storage
Store data locally
Anjan Debnath
SQLite in detail
● Define a schema and contract
● Create a database using an SQL helper
● Put information into a database
● Read information from a database
● Delete information from a database
● Update a database
● Persisting database connection
● Debug your database
Store data locally
Anjan Debnath
Define a schema and contract
● One of the main principles of SQL databases is the schema: a formal
declaration of how the database is organized.
● The schema is reflected in the SQL statements that you use to create your
database.
● You may find it helpful to create a companion class, known as a contract
class, which explicitly specifies the layout of your schema in a
systematic and self-documenting way.
Store data locally
Anjan Debnath
Example
Store data locally
Anjan Debnath
Create a database using an SQL helper
● Once you have defined how your database looks, you should implement
methods that create and maintain the database and tables.
Store data locally
Anjan Debnath
Put information into a database
● To access your database, instantiate your subclass of SQLiteOpenHelper
● Insert data into the database by passing a ContentValues object to
the insert() method
Store data locally
Anjan Debnath
Read information from a database
● To read from a database, use the query() method, passing it your selection
criteria and desired columns.
● The method combines elements of insert() and update(), except the column
list defines the data you want to fetch (the "projection"), rather than the data
to insert.
● The results of the query are returned to you in a Cursor object.
Store data locally
Anjan Debnath
Example
Store data locally
Anjan Debnath
Delete information from a database
● To delete rows from a table, you need to provide selection criteria that identify
the rows to the delete() method.
● The mechanism works the same as the selection arguments to
the query() method.
Store data locally
Anjan Debnath
Example
Store data locally
Anjan Debnath
Update a database
● When you need to modify a subset of your database values, use
the update() method.
Store data locally
Anjan Debnath
Persisting database connection
● You should leave your database connection open for as long as you possibly
need to access it. Typically, it is optimal to close the database in
the onDestroy() of the calling Activity.
Store data locally
Anjan Debnath
Room Persistency Library
● The Room persistence library provides an abstraction layer over SQLite to
allow for more robust database access while harnessing the full power of
SQLite.
● Why Room?
● You have to write long repetitive code, which will be time-consuming as
well as prone to mistakes.
● It is very difficult to manage SQL queries for a complex relational database.
Store data locally
Anjan Debnath
Room Annotation
Store data locally
Anjan Debnath
Room in detail
● Add the gradle dependencies in the build.gradle file.
● Create a data model class for the database table and annotate its table
name and primary key.
● Create an interface class for Database access. Create abstract methods for
CRUD operations. Add custom SQL query as a method.
● Create a Database class for database implementation.
● Declare and initialize an object for the Database class in your Activity or
Fragment class.
Store data locally
Anjan Debnath
Add the gradle dependencies in the build.gradle file.
Store data locally
Anjan Debnath
Create a data model class
Store data locally
Anjan Debnath
Create an interface class for Database access
Store data locally
Anjan Debnath
Create a Database class for database
implementation
Store data locally
Anjan Debnath
Declare and initialize an object for the Database
class
Store data locally
Anjan Debnath
Sample Insert code
Store data locally
Anjan Debnath
Referrence
● https://developer.android.com/training/data-storage/sqlite
● http://demispb.blogspot.com/p/android-development.html
● https://developer.android.com/training/data-storage/room/
● https://medium.freecodecamp.org/room-sqlite-beginner-tutorial-2e725e47bfab
Store data locally
Anjan Debnath
Assignment 1 (Database)
● Create a Movie database.
● Create 2 table name movies and directors.
● The movies table must have movie name and movie id as primary key.
● The directors table must have director name and director id as primary
key.
● Create relation between 2 tables with foreign key.
● Using both SQLite and Room library you have to design your Database
schema and tables.
Store data locally
Anjan Debnath
Assignment 2 (Android App)
● Create an Android app that must have 2 below Activity.
● Activity 1 should have 2 Edit text and a submit button.
● It should be the Sign up page and you should enter user name and password.
● This user name and password should be saved into Shared Preference.
● Use the user name and pass to Sign in.
● Activity 2 should have 2 Edit text and a submit button.
● You have to input Movie name and Director name and clicking on submit
button it should be insert into Database.
● Use a Recycler View to display the Records from database.
Store data locally
Anjan Debnath
Diagram
Store data locally
Anjan Debnath
Mark Distribution
● Shared preference - 2
● SQLite - 3
● Room Library - 3
● Complete assignment - 2
● Total 10
Store data locally
Anjan Debnath
Q/A
Store data locally
Anjan Debnath

More Related Content

What's hot

Introduction to NoSql
Introduction to NoSqlIntroduction to NoSql
Introduction to NoSqlOmid Vahdaty
 
Dynamo db pros and cons
Dynamo db  pros and consDynamo db  pros and cons
Dynamo db pros and consSaniya Khalsa
 
Common Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta LakehouseCommon Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta LakehouseDatabricks
 
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)Tuning and Optimizing U-SQL Queries (SQLPASS 2016)
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)Michael Rys
 
Introduction to aws dynamo db
Introduction to aws dynamo dbIntroduction to aws dynamo db
Introduction to aws dynamo dbOmid Vahdaty
 
Empowering the AWS DynamoDB™ application developer with Alternator
Empowering the AWS DynamoDB™ application developer with AlternatorEmpowering the AWS DynamoDB™ application developer with Alternator
Empowering the AWS DynamoDB™ application developer with AlternatorScyllaDB
 
Delta: Building Merge on Read
Delta: Building Merge on ReadDelta: Building Merge on Read
Delta: Building Merge on ReadDatabricks
 
Amazon Web Services lection 4
Amazon Web Services lection 4  Amazon Web Services lection 4
Amazon Web Services lection 4 Binary Studio
 
Asp #2
Asp #2Asp #2
Asp #2Joni
 
NoSQL and MapReduce
NoSQL and MapReduceNoSQL and MapReduce
NoSQL and MapReduceJ Singh
 
U-SQL Federated Distributed Queries (SQLBits 2016)
U-SQL Federated Distributed Queries (SQLBits 2016)U-SQL Federated Distributed Queries (SQLBits 2016)
U-SQL Federated Distributed Queries (SQLBits 2016)Michael Rys
 
Azure database as a service options
Azure database as a service optionsAzure database as a service options
Azure database as a service optionsMarcelo Adade
 

What's hot (20)

Introduction to NoSql
Introduction to NoSqlIntroduction to NoSql
Introduction to NoSql
 
Dynamo db pros and cons
Dynamo db  pros and consDynamo db  pros and cons
Dynamo db pros and cons
 
Common Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta LakehouseCommon Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta Lakehouse
 
CouchDB
CouchDBCouchDB
CouchDB
 
CouchDB
CouchDBCouchDB
CouchDB
 
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)Tuning and Optimizing U-SQL Queries (SQLPASS 2016)
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)
 
Introduction to aws dynamo db
Introduction to aws dynamo dbIntroduction to aws dynamo db
Introduction to aws dynamo db
 
PHP and Cassandra
PHP and CassandraPHP and Cassandra
PHP and Cassandra
 
Empowering the AWS DynamoDB™ application developer with Alternator
Empowering the AWS DynamoDB™ application developer with AlternatorEmpowering the AWS DynamoDB™ application developer with Alternator
Empowering the AWS DynamoDB™ application developer with Alternator
 
2. react - native: basic
2. react - native: basic2. react - native: basic
2. react - native: basic
 
Delta: Building Merge on Read
Delta: Building Merge on ReadDelta: Building Merge on Read
Delta: Building Merge on Read
 
Dynamo db
Dynamo dbDynamo db
Dynamo db
 
Amazon Web Services lection 4
Amazon Web Services lection 4  Amazon Web Services lection 4
Amazon Web Services lection 4
 
Making Use of Query Layers & Spatial Views
Making Use of Query Layers & Spatial ViewsMaking Use of Query Layers & Spatial Views
Making Use of Query Layers & Spatial Views
 
Asp #2
Asp #2Asp #2
Asp #2
 
NoSQL and MapReduce
NoSQL and MapReduceNoSQL and MapReduce
NoSQL and MapReduce
 
Arango DB
Arango DBArango DB
Arango DB
 
U-SQL Federated Distributed Queries (SQLBits 2016)
U-SQL Federated Distributed Queries (SQLBits 2016)U-SQL Federated Distributed Queries (SQLBits 2016)
U-SQL Federated Distributed Queries (SQLBits 2016)
 
Redis IU
Redis IURedis IU
Redis IU
 
Azure database as a service options
Azure database as a service optionsAzure database as a service options
Azure database as a service options
 

Similar to Store Data Locally in Android Using SQLite, Shared Preferences & Room

Asp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxAsp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxsridharu1981
 
Cloud architectural patterns and Microsoft Azure tools
Cloud architectural patterns and Microsoft Azure toolsCloud architectural patterns and Microsoft Azure tools
Cloud architectural patterns and Microsoft Azure toolsPushkar Chivate
 
Less03 D B D B C A
Less03  D B  D B C ALess03  D B  D B C A
Less03 D B D B C Avivaankumar
 
Core Java Programming Language (JSE) : Chapter XIII - JDBC
Core Java Programming Language (JSE) : Chapter XIII -  JDBCCore Java Programming Language (JSE) : Chapter XIII -  JDBC
Core Java Programming Language (JSE) : Chapter XIII - JDBCWebStackAcademy
 
NDC Minnesota - Analyzing StackExchange data with Azure Data Lake
NDC Minnesota - Analyzing StackExchange data with Azure Data LakeNDC Minnesota - Analyzing StackExchange data with Azure Data Lake
NDC Minnesota - Analyzing StackExchange data with Azure Data LakeTom Kerkhove
 
Sql portfolio admin_practicals
Sql portfolio admin_practicalsSql portfolio admin_practicals
Sql portfolio admin_practicalsShelli Ciaschini
 
Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...
Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...
Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...Amazon Web Services
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Modelkunj desai
 
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...Knut Relbe-Moe [MVP, MCT]
 
Design Considerations For Storing With Windows Azure
Design Considerations For Storing With Windows AzureDesign Considerations For Storing With Windows Azure
Design Considerations For Storing With Windows AzureEric Nelson
 
Amazon RedShift - Ianni Vamvadelis
Amazon RedShift - Ianni VamvadelisAmazon RedShift - Ianni Vamvadelis
Amazon RedShift - Ianni Vamvadelishuguk
 
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB AtlasMongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB AtlasMongoDB
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDBvaluebound
 
Tuning SQL Server for Sharepoint-Sharepoint Summit Toronto 2014
Tuning SQL Server for Sharepoint-Sharepoint Summit Toronto 2014Tuning SQL Server for Sharepoint-Sharepoint Summit Toronto 2014
Tuning SQL Server for Sharepoint-Sharepoint Summit Toronto 2014serge luca
 
Optimize SQL server performance for SharePoint
Optimize SQL server performance for SharePointOptimize SQL server performance for SharePoint
Optimize SQL server performance for SharePointserge luca
 
Tuning SQL Server for Sharepoint 2013- What every sharepoint consultant need...
Tuning SQL Server for Sharepoint 2013-  What every sharepoint consultant need...Tuning SQL Server for Sharepoint 2013-  What every sharepoint consultant need...
Tuning SQL Server for Sharepoint 2013- What every sharepoint consultant need...serge luca
 

Similar to Store Data Locally in Android Using SQLite, Shared Preferences & Room (20)

ora_sothea
ora_sotheaora_sothea
ora_sothea
 
Asp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptxAsp .Net Database Connectivity Presentation.pptx
Asp .Net Database Connectivity Presentation.pptx
 
Cloud architectural patterns and Microsoft Azure tools
Cloud architectural patterns and Microsoft Azure toolsCloud architectural patterns and Microsoft Azure tools
Cloud architectural patterns and Microsoft Azure tools
 
Sql Portfolio
Sql PortfolioSql Portfolio
Sql Portfolio
 
Less03 D B D B C A
Less03  D B  D B C ALess03  D B  D B C A
Less03 D B D B C A
 
Spring Data JPA
Spring Data JPASpring Data JPA
Spring Data JPA
 
Core Java Programming Language (JSE) : Chapter XIII - JDBC
Core Java Programming Language (JSE) : Chapter XIII -  JDBCCore Java Programming Language (JSE) : Chapter XIII -  JDBC
Core Java Programming Language (JSE) : Chapter XIII - JDBC
 
NDC Minnesota - Analyzing StackExchange data with Azure Data Lake
NDC Minnesota - Analyzing StackExchange data with Azure Data LakeNDC Minnesota - Analyzing StackExchange data with Azure Data Lake
NDC Minnesota - Analyzing StackExchange data with Azure Data Lake
 
Sql portfolio admin_practicals
Sql portfolio admin_practicalsSql portfolio admin_practicals
Sql portfolio admin_practicals
 
PHP Oracle
PHP OraclePHP Oracle
PHP Oracle
 
Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...
Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...
Accelerating Application Development with Amazon Aurora (DAT312-R2) - AWS re:...
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
 
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
 
Design Considerations For Storing With Windows Azure
Design Considerations For Storing With Windows AzureDesign Considerations For Storing With Windows Azure
Design Considerations For Storing With Windows Azure
 
Amazon RedShift - Ianni Vamvadelis
Amazon RedShift - Ianni VamvadelisAmazon RedShift - Ianni Vamvadelis
Amazon RedShift - Ianni Vamvadelis
 
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB AtlasMongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
 
The Basics of MongoDB
The Basics of MongoDBThe Basics of MongoDB
The Basics of MongoDB
 
Tuning SQL Server for Sharepoint-Sharepoint Summit Toronto 2014
Tuning SQL Server for Sharepoint-Sharepoint Summit Toronto 2014Tuning SQL Server for Sharepoint-Sharepoint Summit Toronto 2014
Tuning SQL Server for Sharepoint-Sharepoint Summit Toronto 2014
 
Optimize SQL server performance for SharePoint
Optimize SQL server performance for SharePointOptimize SQL server performance for SharePoint
Optimize SQL server performance for SharePoint
 
Tuning SQL Server for Sharepoint 2013- What every sharepoint consultant need...
Tuning SQL Server for Sharepoint 2013-  What every sharepoint consultant need...Tuning SQL Server for Sharepoint 2013-  What every sharepoint consultant need...
Tuning SQL Server for Sharepoint 2013- What every sharepoint consultant need...
 

Recently uploaded

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 

Store Data Locally in Android Using SQLite, Shared Preferences & Room

  • 3. Store data locally Anjan Debnath Ways to store data in Android
  • 4. Store data locally Anjan Debnath Shared Preference
  • 5. Store data locally Anjan Debnath SQLite
  • 6. Store data locally Anjan Debnath File Storage
  • 7. Store data locally Anjan Debnath Content Provider
  • 8. Store data locally Anjan Debnath Cloud Storage
  • 9. Store data locally Anjan Debnath SQLite in detail ● Define a schema and contract ● Create a database using an SQL helper ● Put information into a database ● Read information from a database ● Delete information from a database ● Update a database ● Persisting database connection ● Debug your database
  • 10. Store data locally Anjan Debnath Define a schema and contract ● One of the main principles of SQL databases is the schema: a formal declaration of how the database is organized. ● The schema is reflected in the SQL statements that you use to create your database. ● You may find it helpful to create a companion class, known as a contract class, which explicitly specifies the layout of your schema in a systematic and self-documenting way.
  • 11. Store data locally Anjan Debnath Example
  • 12. Store data locally Anjan Debnath Create a database using an SQL helper ● Once you have defined how your database looks, you should implement methods that create and maintain the database and tables.
  • 13. Store data locally Anjan Debnath Put information into a database ● To access your database, instantiate your subclass of SQLiteOpenHelper ● Insert data into the database by passing a ContentValues object to the insert() method
  • 14. Store data locally Anjan Debnath Read information from a database ● To read from a database, use the query() method, passing it your selection criteria and desired columns. ● The method combines elements of insert() and update(), except the column list defines the data you want to fetch (the "projection"), rather than the data to insert. ● The results of the query are returned to you in a Cursor object.
  • 15. Store data locally Anjan Debnath Example
  • 16. Store data locally Anjan Debnath Delete information from a database ● To delete rows from a table, you need to provide selection criteria that identify the rows to the delete() method. ● The mechanism works the same as the selection arguments to the query() method.
  • 17. Store data locally Anjan Debnath Example
  • 18. Store data locally Anjan Debnath Update a database ● When you need to modify a subset of your database values, use the update() method.
  • 19. Store data locally Anjan Debnath Persisting database connection ● You should leave your database connection open for as long as you possibly need to access it. Typically, it is optimal to close the database in the onDestroy() of the calling Activity.
  • 20. Store data locally Anjan Debnath Room Persistency Library ● The Room persistence library provides an abstraction layer over SQLite to allow for more robust database access while harnessing the full power of SQLite. ● Why Room? ● You have to write long repetitive code, which will be time-consuming as well as prone to mistakes. ● It is very difficult to manage SQL queries for a complex relational database.
  • 21. Store data locally Anjan Debnath Room Annotation
  • 22. Store data locally Anjan Debnath Room in detail ● Add the gradle dependencies in the build.gradle file. ● Create a data model class for the database table and annotate its table name and primary key. ● Create an interface class for Database access. Create abstract methods for CRUD operations. Add custom SQL query as a method. ● Create a Database class for database implementation. ● Declare and initialize an object for the Database class in your Activity or Fragment class.
  • 23. Store data locally Anjan Debnath Add the gradle dependencies in the build.gradle file.
  • 24. Store data locally Anjan Debnath Create a data model class
  • 25. Store data locally Anjan Debnath Create an interface class for Database access
  • 26. Store data locally Anjan Debnath Create a Database class for database implementation
  • 27. Store data locally Anjan Debnath Declare and initialize an object for the Database class
  • 28. Store data locally Anjan Debnath Sample Insert code
  • 29. Store data locally Anjan Debnath Referrence ● https://developer.android.com/training/data-storage/sqlite ● http://demispb.blogspot.com/p/android-development.html ● https://developer.android.com/training/data-storage/room/ ● https://medium.freecodecamp.org/room-sqlite-beginner-tutorial-2e725e47bfab
  • 30. Store data locally Anjan Debnath Assignment 1 (Database) ● Create a Movie database. ● Create 2 table name movies and directors. ● The movies table must have movie name and movie id as primary key. ● The directors table must have director name and director id as primary key. ● Create relation between 2 tables with foreign key. ● Using both SQLite and Room library you have to design your Database schema and tables.
  • 31. Store data locally Anjan Debnath Assignment 2 (Android App) ● Create an Android app that must have 2 below Activity. ● Activity 1 should have 2 Edit text and a submit button. ● It should be the Sign up page and you should enter user name and password. ● This user name and password should be saved into Shared Preference. ● Use the user name and pass to Sign in. ● Activity 2 should have 2 Edit text and a submit button. ● You have to input Movie name and Director name and clicking on submit button it should be insert into Database. ● Use a Recycler View to display the Records from database.
  • 32. Store data locally Anjan Debnath Diagram
  • 33. Store data locally Anjan Debnath Mark Distribution ● Shared preference - 2 ● SQLite - 3 ● Room Library - 3 ● Complete assignment - 2 ● Total 10