SlideShare a Scribd company logo
©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

PPTX
Introduction to NoSQL Database
PPTX
Google BigQuery 101 & What’s New
PPTX
How to Design a Modern Data Warehouse in BigQuery
PPTX
MongoDB - A next-generation database that lets you create applications never ...
PDF
Evolution of Spark APIs
PPTX
Columnstore Customer Stories 2016 by Sunil Agarwal
PPTX
Using Cassandra with your Web Application
PDF
Introduction to NoSQL Database
Google BigQuery 101 & What’s New
How to Design a Modern Data Warehouse in BigQuery
MongoDB - A next-generation database that lets you create applications never ...
Evolution of Spark APIs
Columnstore Customer Stories 2016 by Sunil Agarwal
Using Cassandra with your Web Application

What's hot (20)

PPTX
Introduction to NoSql
DOCX
Dynamo db pros and cons
PDF
Common Strategies for Improving Performance on Your Delta Lakehouse
PDF
CouchDB
PPT
PPTX
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)
PPTX
Introduction to aws dynamo db
PPTX
PHP and Cassandra
PPTX
Empowering the AWS DynamoDB™ application developer with Alternator
PPTX
2. react - native: basic
PDF
Delta: Building Merge on Read
PPTX
Dynamo db
PPTX
Amazon Web Services lection 4
PPTX
Making Use of Query Layers & Spatial Views
PPT
Asp #2
PPTX
NoSQL and MapReduce
PPTX
U-SQL Federated Distributed Queries (SQLBits 2016)
ODP
Redis IU
PPTX
Azure database as a service options
Introduction to NoSql
Dynamo db pros and cons
Common Strategies for Improving Performance on Your Delta Lakehouse
CouchDB
Tuning and Optimizing U-SQL Queries (SQLPASS 2016)
Introduction to aws dynamo db
PHP and Cassandra
Empowering the AWS DynamoDB™ application developer with Alternator
2. react - native: basic
Delta: Building Merge on Read
Dynamo db
Amazon Web Services lection 4
Making Use of Query Layers & Spatial Views
Asp #2
NoSQL and MapReduce
U-SQL Federated Distributed Queries (SQLBits 2016)
Redis IU
Azure database as a service options
Ad

Similar to Save data locally (20)

PPT
ora_sothea
PPTX
Asp .Net Database Connectivity Presentation.pptx
PPTX
111111112222223333335555555666Unit-4.pptx
PPTX
Cloud architectural patterns and Microsoft Azure tools
PPT
Sql Portfolio
PPT
Less03 D B D B C A
PDF
Spring Data JPA
PDF
Core Java Programming Language (JSE) : Chapter XIII - JDBC
PPTX
NDC Minnesota - Analyzing StackExchange data with Azure Data Lake
PPT
Sql portfolio admin_practicals
PPTX
PHP Oracle
PPT
JDBC Connectivity Model
PPTX
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
PPTX
Design Considerations For Storing With Windows Azure
PDF
Amazon RedShift - Ianni Vamvadelis
PDF
monfodb for full stack programmers good.
PDF
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
PPTX
The Basics of MongoDB
PPTX
Tuning SQL Server for Sharepoint-Sharepoint Summit Toronto 2014
PPTX
Optimize SQL server performance for SharePoint
ora_sothea
Asp .Net Database Connectivity Presentation.pptx
111111112222223333335555555666Unit-4.pptx
Cloud architectural patterns and Microsoft Azure tools
Sql Portfolio
Less03 D B D B C A
Spring Data JPA
Core Java Programming Language (JSE) : Chapter XIII - JDBC
NDC Minnesota - Analyzing StackExchange data with Azure Data Lake
Sql portfolio admin_practicals
PHP Oracle
JDBC Connectivity Model
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Design Considerations For Storing With Windows Azure
Amazon RedShift - Ianni Vamvadelis
monfodb for full stack programmers good.
MongoDB World 2019: Packing Up Your Data and Moving to MongoDB Atlas
The Basics of MongoDB
Tuning SQL Server for Sharepoint-Sharepoint Summit Toronto 2014
Optimize SQL server performance for SharePoint
Ad

Recently uploaded (20)

PPTX
Cell Structure & Organelles in detailed.
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Institutional Correction lecture only . . .
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
master seminar digital applications in india
PDF
Classroom Observation Tools for Teachers
PPTX
Cell Types and Its function , kingdom of life
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Cell Structure & Organelles in detailed.
Microbial disease of the cardiovascular and lymphatic systems
Institutional Correction lecture only . . .
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
GDM (1) (1).pptx small presentation for students
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
master seminar digital applications in india
Classroom Observation Tools for Teachers
Cell Types and Its function , kingdom of life
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Final Presentation General Medicine 03-08-2024.pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Complications of Minimal Access Surgery at WLH
O5-L3 Freight Transport Ops (International) V1.pdf
Final Presentation General Medicine 03-08-2024.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Supply Chain Operations Speaking Notes -ICLT Program
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE

Save data locally

  • 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