SlideShare a Scribd company logo
Android Programming




   Lesson 7
Data Storage

 NGUYEN The Linh
Android Programming


Contents

     1     Accessing Files

     2     Using Preferences

     3     Accessing Local Database


     4     Exercise 7




                             2
Android Programming


Data Storage




           Accessing Files




                 3
Android Programming


Accessing Files

 Including Static Files as Resources
    If your application requires external file resources, you can include
     them in your distribution package by placing them in the res/raw
     folder of your project hierarchy.




                                   4
Android Programming


Accessing Files

 Including Static Files as Resources (etc.)
    Adding raw files to your resources hierarchy is an excellent
     alternative for large, preexisting data sources (such as
     dictionaries) where it’s not desirable (or even possible) to convert
     them into an Android database.




                                   5
Android Programming


Accessing Files

 Accessing File from SDCard
    Permission
      • <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


    SDCard Path
      • Environment.getExternalStorageDirectory().getAbsolutePath()


    Check a file is exists or not
      • /sdcard/contacts.xml



                                     6
Android Programming


Accessing Files

 Accessing File from SDCard(etc. )
    Check a file is exists or not




                          7
Android Programming


Accessing Files

 Accessing File from SDCard(etc. )
    Create New File




                          8
Android Programming


Accessing Files

 Accessing File from SDCard(etc. )
    Delete File




                          9
Android Programming


Accessing Files

 Example 7.1
    Update Exercise 6 project:
       • Data will be loaded from /raw/contacts.xml




                                       10
Android Programming


Accessing Files

 Example 7.2
    Update Exercise 6 project:
       • Data will be stored in SDCard




                                         11
Android Programming


Data Storage




               Shared Preferences




                      12
Android Programming


Shared Preference

 Using SharedPreferences, you can create named maps
  of key/value pairs within your application that can be
  shared between application components running in
  the same Context.

 Shared Preferences support the primitive types
  Boolean, string, float, long, and integer, making them
  an ideal way to quickly store default values, class
  instance variables, the current UI state, and user
  preferences.


                          13
Android Programming


Shared Preference




                    14
Android Programming


Shared Preference




                    15
Android Programming


Shared Preference

 Example 7.3
    Update Example 7.2 project:
       • Prompt engaged users to rate your app
         in the Google Play




                                     16
Android Programming


Data Storage




         Accessing Local Database




                   17
Android Programming


Accessing Local Database

 Install a Firefox Add-on: SQLite manager
    https://addons.mozilla.org/vi/firefox/addon/sqlite-manager/




                                  18
Android Programming


Accessing Local Database

 Create Helper class
    It’s good practice to create a helper class to simplify your
     database interactions.
    BaseDAO class will be provided
    Add database file (demo.sqlite) to assets folder
    Open BaseDAO class and change DB_NAME = “demo.sqlite”




                                19
Android Programming


Accessing Local Database

 Using the BaseDAO class
    Check and create DB




                        20
Android Programming


Accessing Local Database

 Using the BaseDAO class
    Add new row




                        21
Android Programming


Accessing Local Database

 Using the BaseDAO class
    Add new row




                        22
Android Programming


Accessing Local Database

 Using the BaseDAO class
    Select rows




                        23
Android Programming


Accessing Local Database

 Using the BaseDAO class
    Delete a row




                        24
Android Programming


Accessing Local Database

 Using the BaseDAO class
    Update a row




                        25
Android Programming


Exercise 7

 Update Exercise 6 project:
    Data will be stored in SQLite database




                                26
Android Programming

More Related Content

What's hot (20)

PPT
Persistences
Training Guide
 
PPT
SQLITE Android
Sourabh Sahu
 
ODP
Android App Development - 09 Storage
Diego Grancini
 
PDF
Android Data Persistence
Romain Rochegude
 
PDF
Android App Development 05 : Saving Data
Anuchit Chalothorn
 
PDF
SQLite Database Tutorial In Android
Android 5
 
PPTX
Storage 8
Michael Shrove
 
PPTX
Databases in Android Application
Mark Lester Navarro
 
PPTX
Android Database Tutorial
Perfect APK
 
PPTX
Android Training (Java Review)
Khaled Anaqwa
 
DOCX
Android database tutorial
info_zybotech
 
PDF
Persitance Data with sqlite
Arif Huda
 
PPT
Shared preferences
Sourabh Sahu
 
PPTX
Database in Android
MaryadelMar85
 
DOCX
Accessing data with android cursors
info_zybotech
 
PDF
03 programmation mobile - android - (stockage, multithreads, web services)
TECOS
 
PPTX
09.1. Android - Local Database (Sqlite)
Oum Saokosal
 
PPTX
android sqlite
Deepa Rani
 
PDF
02 programmation mobile - android - (activity, view, fragment)
TECOS
 
PDF
Local data storage for mobile apps
Ivano Malavolta
 
Persistences
Training Guide
 
SQLITE Android
Sourabh Sahu
 
Android App Development - 09 Storage
Diego Grancini
 
Android Data Persistence
Romain Rochegude
 
Android App Development 05 : Saving Data
Anuchit Chalothorn
 
SQLite Database Tutorial In Android
Android 5
 
Storage 8
Michael Shrove
 
Databases in Android Application
Mark Lester Navarro
 
Android Database Tutorial
Perfect APK
 
Android Training (Java Review)
Khaled Anaqwa
 
Android database tutorial
info_zybotech
 
Persitance Data with sqlite
Arif Huda
 
Shared preferences
Sourabh Sahu
 
Database in Android
MaryadelMar85
 
Accessing data with android cursors
info_zybotech
 
03 programmation mobile - android - (stockage, multithreads, web services)
TECOS
 
09.1. Android - Local Database (Sqlite)
Oum Saokosal
 
android sqlite
Deepa Rani
 
02 programmation mobile - android - (activity, view, fragment)
TECOS
 
Local data storage for mobile apps
Ivano Malavolta
 

Viewers also liked (13)

PDF
Android Storage - StorageManager & OBB
William Lee
 
PDF
[Android] Basic Widgets and Containers
Nikmesoft Ltd
 
PDF
[Android] Using Selection Widgets
Nikmesoft Ltd
 
PDF
[iOS] Introduction to iOS Programming
Nikmesoft Ltd
 
PDF
[iOS] Networking
Nikmesoft Ltd
 
PDF
Objective-C
Giuseppe Arici
 
PDF
[Android] Introduction to Android Programming
Nikmesoft Ltd
 
PDF
[Android] Intent and Activity
Nikmesoft Ltd
 
PDF
[Android] Widget Event Handling
Nikmesoft Ltd
 
PDF
Introduction to Swift programming language.
Icalia Labs
 
PPTX
Apple iOS
Chetan Gowda
 
PPTX
Mobile operating system ppt
Santosh Kumar
 
PDF
Android Storage - Vold
William Lee
 
Android Storage - StorageManager & OBB
William Lee
 
[Android] Basic Widgets and Containers
Nikmesoft Ltd
 
[Android] Using Selection Widgets
Nikmesoft Ltd
 
[iOS] Introduction to iOS Programming
Nikmesoft Ltd
 
[iOS] Networking
Nikmesoft Ltd
 
Objective-C
Giuseppe Arici
 
[Android] Introduction to Android Programming
Nikmesoft Ltd
 
[Android] Intent and Activity
Nikmesoft Ltd
 
[Android] Widget Event Handling
Nikmesoft Ltd
 
Introduction to Swift programming language.
Icalia Labs
 
Apple iOS
Chetan Gowda
 
Mobile operating system ppt
Santosh Kumar
 
Android Storage - Vold
William Lee
 
Ad

Similar to [Android] Data Storage (20)

PPT
Android activity, service, and broadcast recievers
Jagdish Gediya
 
PDF
Android development training programme Day 1
DHIRAJ PRAVIN
 
PPTX
Ii 1300-java essentials for android
Adrian Mikeliunas
 
PPTX
Android cours
zakaria bentahar
 
PPTX
Introduction to android
zeelpatel0504
 
PPT
Android development tutorial
nazzf
 
PPT
Android Introduction
aswapnal
 
PPTX
Android development tutorial
Mohammad Taj
 
PDF
Introduction to android
krishnastudent88
 
PDF
Is Java Required for Android App Development.pdf
Indian Website Company
 
PDF
Android Development
vishalkrv
 
PDF
ID Android TechTalk Series #6 : Google Service and Gradle - Anton Nurdin Tuha...
Dicoding
 
DOC
Google android white paper
Sravan Reddy
 
PPTX
Android development classes in chandigarh : Big Boxx Academy
Big Boxx Animation Academy
 
PPTX
Androidoverview 100405150711-phpapp01
Santosh Sh
 
PPT
Android
Ravi Babu
 
PDF
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
DuckMa
 
PPT
"Android" mobilių programėlių kūrimo įvadas #3
Tadas Jurelevičius
 
PPSX
My android
Prince Bhanwra
 
PPSX
My android
Prince Bhanwra
 
Android activity, service, and broadcast recievers
Jagdish Gediya
 
Android development training programme Day 1
DHIRAJ PRAVIN
 
Ii 1300-java essentials for android
Adrian Mikeliunas
 
Android cours
zakaria bentahar
 
Introduction to android
zeelpatel0504
 
Android development tutorial
nazzf
 
Android Introduction
aswapnal
 
Android development tutorial
Mohammad Taj
 
Introduction to android
krishnastudent88
 
Is Java Required for Android App Development.pdf
Indian Website Company
 
Android Development
vishalkrv
 
ID Android TechTalk Series #6 : Google Service and Gradle - Anton Nurdin Tuha...
Dicoding
 
Google android white paper
Sravan Reddy
 
Android development classes in chandigarh : Big Boxx Academy
Big Boxx Animation Academy
 
Androidoverview 100405150711-phpapp01
Santosh Sh
 
Android
Ravi Babu
 
Matteo Gazzurelli - Introduction to Android Development - Have a break edition
DuckMa
 
"Android" mobilių programėlių kūrimo įvadas #3
Tadas Jurelevičius
 
My android
Prince Bhanwra
 
My android
Prince Bhanwra
 
Ad

More from Nikmesoft Ltd (11)

PDF
[iOS] Data Storage
Nikmesoft Ltd
 
PDF
[iOS] Multiple Background Threads
Nikmesoft Ltd
 
PDF
[iOS] Navigation
Nikmesoft Ltd
 
PDF
[iOS] Basic UI Elements
Nikmesoft Ltd
 
PDF
[Android] Multimedia Programming
Nikmesoft Ltd
 
PDF
[Android] Android Animation
Nikmesoft Ltd
 
PDF
[Android] 2D Graphics
Nikmesoft Ltd
 
PDF
[Android] Services and Broadcast Receivers
Nikmesoft Ltd
 
PDF
[Android] Web services
Nikmesoft Ltd
 
PDF
[Android] Multiple Background Threads
Nikmesoft Ltd
 
PDF
[Android] Maps, Geocoding and Location-Based Services
Nikmesoft Ltd
 
[iOS] Data Storage
Nikmesoft Ltd
 
[iOS] Multiple Background Threads
Nikmesoft Ltd
 
[iOS] Navigation
Nikmesoft Ltd
 
[iOS] Basic UI Elements
Nikmesoft Ltd
 
[Android] Multimedia Programming
Nikmesoft Ltd
 
[Android] Android Animation
Nikmesoft Ltd
 
[Android] 2D Graphics
Nikmesoft Ltd
 
[Android] Services and Broadcast Receivers
Nikmesoft Ltd
 
[Android] Web services
Nikmesoft Ltd
 
[Android] Multiple Background Threads
Nikmesoft Ltd
 
[Android] Maps, Geocoding and Location-Based Services
Nikmesoft Ltd
 

Recently uploaded (20)

PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Timothy Rottach - Ramp up on AI Use Cases, from Vector Search to AI Agents wi...
AWS Chicago
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
July Patch Tuesday
Ivanti
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Python basic programing language for automation
DanialHabibi2
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 

[Android] Data Storage