SlideShare a Scribd company logo
BY: AKASH UGALE
Data Sores in Android
Operating System
Data Storage In Android
Shared Preferences:-Store private primitive data in
key-value pairs.
Internal Storage:-Store private data on the device
memory.
External Storage:-Store public data on the shared
external storage.
SQLite Databases:-Store structured data in a
private database.
Network Connection:-Store data on the web with
your own network server.
Shared Preferences
Useful for storing and retrieving primitive
data in key value pairs.
Lightweight usage, such as saving application
settings.
Typical usage of SharedPreferences is for saving
application such as username and password,
auto login flag, remember-user flag etc.
Shared Preferences Contd…..
The shared preferences information is stored in
an XML file on the device
 Typically in/data/data/<Your Application’s package
name>/shared_prefs
SharedPreferences can be associated with the entire
application, or to a specific activity.
Use the getSharedPrefernces() method to get access
to the preferences
Shared Preferences Contd…..
Example:
 SharedPrefernces prefs = this.getSharedPrefernces(‘myPrefs,
MODE_PRIVATE’)
If the preferences XML file exist, it is opened,
otherwise it is created.
To Control access permission to the file:
 MODE_PRIVATE:private only to the application
 MODE_WORLD_READABLE:all application can read XML file
 MODE_WORLD_WRITABLE:all application can write XML file
Shared Preferences Contd…..
To add Shared preferences, first an editor object is
needed
 Editor prefsEditor = prefs.edit();
Then,use the put() method to add the key-value pairs
 prefsEditor.putString(“username”,”D-Link”);
 prefsEditor.putString(“password”,”vlsi#1@2”);
 prefsEditor.putint(“times-login”,1);
 prefsEditor.commit();
Shared Preferences Contd…..
To retrieve shared preferences data:
 String username = prefsEditor.getString(“username”.” ”);
 String password = prefsEditor.getString(“password”.” ”);
If you are using SharedPrefernces for specific
activity, then use getPreferences() method
 No need to specify the name of the preferences file
Example
Internal Storage
Android can save files directly to the device
internal storage.
These files are private to the application and will
be removed if you uninstall the application.
We can create a file using openFileOutput() with
parameter as file name and the operating mode.
Generally not recommended to use files.
Internal Storage Contd….
Similarly, we can open the file using
openFileInput() passing the parameter as the
filename with extension.
File are use to store large amount of data
Use I/O interfaces provided by java.io.* libraries
to read/write files.
Only local files can be accessed.
File Operation(Read)
Use context.openFileInput(string name) to
open a private input file stream related to a program.
Throw FileNotFoundException when file does
not exist.
Syntax:-
fileinputStram.in=this.openfileinput(“xyz.txt”)
.
.
.
.
.
In.close()://Close input stream
File Operation (Write)
Use context.openFileOutput(string name,int
mode ) to open a private output file stream related
to a program.
The file will be created if it does not exist.
Output stream can be opened in append mode,
which means new data will be appended to end of
the file.
String mystring=“Hello World”
File Operation (write) Contd….
Syntax:-
FileOutputStream outfile = this.openFileOutput(“myfile.txt”,MODE_APPEND)
//Open and Write in”myfile.txt”,using append mode.
Outfile.write(mystring.getBytes());
Outfile.close();//close output stream
External Storage
Every Android-compatible device supports a shared
“external storage” that you can use to save files
 Removable storage media (such as an SD card)
 Internal (non-removable) storage
File saved to the external storage are world readable
and can be modified by the user when they enable
USB mass storage to transfer files on computer.
These files are private to the application and will
be removed when the application is uninstalled.
External Storage Continue
Must check whether external storage is available first
by calling getExternalStorageState()
 Also check whether it allows read/write before reading/writing
on it
getExternalFilesDir() takes a parameter such as
DIRECTORY_MUSIC,DIRECTORY_RINGTONE
etc,to open specific type of subdirectories.
For public shared directories,use
getExternalStoragePublicDirectory()
External Storage Contd…..
For cache files,use getExternalCacheDir()
All these are applicable for API level 8 or above
For API level 7 or below ,use the method;
 getExternalStorageDirectory()
 Private files stored in//Android/data/<package_name>/files/
 Cache files stored in//Android/data/<package_name>/cache/
Example
SQLite Databases
android.database.sqlite Contains the SQLite
database management classes that an application
would use to manage its own private database.
android.database.sqlite.SQLiteDatabase
Contains the methods for: creating, opening, closing,
inserting, updating, deleting and quering an SQLite
database.
android.database.sqlite - Classes
 SQLiteCloseable - An object created from a SQLiteDatabase that can be
closed.
 SQLiteCursor - A Cursor implementation that exposes results from a
query on a SQLiteDatabase.
 SQLiteDatabase - Exposes methods to manage a SQLite database.
 SQLiteOpenHelper - A helper class to manage database creation and
version management.
 SQLiteProgram - A base class for compiled SQLite programs.
 SQLiteQuery - A SQLite program that represents a query that reads the
resulting rows into a CursorWindow.
 SQLiteQueryBuilder - a convenience class that helps build SQL queries
to be sent to SQLiteDatabase objects.
 SQLiteStatement - A pre-compiled statement against a SQLiteDatabase
that can be reused.
OpenOrCreateDatabase
This method will open an existing database or create
one in the application data area
 import android.database.sqlite.SQLiteDatabase;
SQLiteDatabase myDatabase;
myDatabase = openOrCreateDatabase ("my_sqlite_database.db" ,
SQLiteDatabase.CREATE_IF_NECESSARY , null);
Creating Tables
Create a static string containing the SQLite
CREATE statement, use the execSQL( ) method to
execute it.
 String createAuthor = "CREAT TABLE authors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
fname TEXT,
lname TEXT);
myDatabase.execSQL(createAuthor);
insert( ), delete( )
long insert(String table, String nullColumnHack,
ContentValues values)
import android.content.ContentValues;
ContentValues values = new ContentValues( );
values.put("firstname" , "J.K.");
values.put("lastname" , "Rowling");
long newAuthorID = myDatabase.insert("tbl_authors" , "" ,
values);
int delete(String table, String whereClause, String[]
whereArgs)
public void deleteBook(Integer bookId) {
myDatabase.delete("tbl_books" , "id=?" ,
new String[ ] { bookId.toString( ) } ) ;
}
Update()
int update(String table, ContentValues values, String
whereClause, String[ ] whereArgs)
public void updateBookTitle(Integer bookId, String newTitle) {
ContentValues values = new ContentValues();
values.put("title" , newTitle);
myDatabase.update("tbl_books" , values ,
"id=?" , new String[ ] {bookId.toString() } );
}
SQLite Storage
Content Provider
Cloud Storage
 Online file storage
centres or cloud
storage providers
allow you to safely
upload your files
to the Internet.
Cloud Storage Contd…..
There are various providers of cloud storage
Examples:
Apple iCloud(Gives 5GB of free storage )
Dropbox(Gives 2GB of free storage )
Google Drive(Gives 15GB of free storage )
Amazon Cloud Drive(Gives 5GB of free storage
Microsoft SkyDrive(Gives 7GB of free storage )
Example
Data Storage In Android

More Related Content

What's hot

Android UI
Android UIAndroid UI
Android UI
nationalmobileapps
 
Fragment
Fragment Fragment
Notification android
Notification androidNotification android
Notification android
ksheerod shri toshniwal
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
Shakib Hasan Sumon
 
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android
DivyaKS12
 
Android Widget
Android WidgetAndroid Widget
Android Widget
ELLURU Kalyan
 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycle
Soham Patel
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
Yong Heui Cho
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
Prawesh Shrestha
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
CodeAndroid
 
Android resource
Android resourceAndroid resource
Android resourceKrazy Koder
 
Android - Android Intent Types
Android - Android Intent TypesAndroid - Android Intent Types
Android - Android Intent Types
Vibrant Technologies & Computers
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
Osahon Gino Ediagbonya
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
vishal choudhary
 
Android share preferences
Android share preferencesAndroid share preferences
Android share preferences
Ajay Panchal
 
Android Fragment
Android FragmentAndroid Fragment
Android Fragment
Kan-Han (John) Lu
 

What's hot (20)

AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Android UI
Android UIAndroid UI
Android UI
 
Fragment
Fragment Fragment
Fragment
 
Notification android
Notification androidNotification android
Notification android
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
 
Java awt
Java awtJava awt
Java awt
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android
 
Android Widget
Android WidgetAndroid Widget
Android Widget
 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycle
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
 
Android resource
Android resourceAndroid resource
Android resource
 
Android - Android Intent Types
Android - Android Intent TypesAndroid - Android Intent Types
Android - Android Intent Types
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
Android share preferences
Android share preferencesAndroid share preferences
Android share preferences
 
Android Fragment
Android FragmentAndroid Fragment
Android Fragment
 

Similar to Data Storage In Android

Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
Dr. Ramkumar Lakshminarayanan
 
Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)
Khaled Anaqwa
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
Matteo Bonifazi
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx
FaezNasir
 
Android App Development - 09 Storage
Android App Development - 09 StorageAndroid App Development - 09 Storage
Android App Development - 09 Storage
Diego Grancini
 
Data management
Data managementData management
Data management
Madrasah Idrisiah
 
Data management
Data managementData management
Data management
maamir farooq
 
Assets, files, and data parsing
Assets, files, and data parsingAssets, files, and data parsing
Assets, files, and data parsing
Aly Arman
 
03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)TECOS
 
Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behestee
Hussain Behestee
 
Mobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdfMobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdf
AbdullahMunir32
 
Persistence on iOS
Persistence on iOSPersistence on iOS
Persistence on iOS
Make School
 
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted NewardAndroid | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
JAX London
 
Memory management
Memory managementMemory management
Memory management
Vikash Patel
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving DataAnuchit Chalothorn
 
Tk2323 lecture 7 data storage
Tk2323 lecture 7   data storageTk2323 lecture 7   data storage
Tk2323 lecture 7 data storage
MengChun Lam
 
Everything about storage - DroidconMtl 2015
Everything about storage - DroidconMtl 2015Everything about storage - DroidconMtl 2015
Everything about storage - DroidconMtl 2015
Cindy Potvin
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP
Nguyen Tuan
 

Similar to Data Storage In Android (20)

Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
 
Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx
 
Android App Development - 09 Storage
Android App Development - 09 StorageAndroid App Development - 09 Storage
Android App Development - 09 Storage
 
Data management
Data managementData management
Data management
 
Data management
Data managementData management
Data management
 
Assets, files, and data parsing
Assets, files, and data parsingAssets, files, and data parsing
Assets, files, and data parsing
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)
 
Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behestee
 
Mobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdfMobile Application Development-Lecture 13 & 14.pdf
Mobile Application Development-Lecture 13 & 14.pdf
 
Persistence on iOS
Persistence on iOSPersistence on iOS
Persistence on iOS
 
Storage 8
Storage   8Storage   8
Storage 8
 
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted NewardAndroid | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
 
Memory management
Memory managementMemory management
Memory management
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving Data
 
Tk2323 lecture 7 data storage
Tk2323 lecture 7   data storageTk2323 lecture 7   data storage
Tk2323 lecture 7 data storage
 
Everything about storage - DroidconMtl 2015
Everything about storage - DroidconMtl 2015Everything about storage - DroidconMtl 2015
Everything about storage - DroidconMtl 2015
 
09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP09.Local Database Files and Storage on WP
09.Local Database Files and Storage on WP
 

Recently uploaded

power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 

Recently uploaded (20)

power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 

Data Storage In Android

  • 1. BY: AKASH UGALE Data Sores in Android Operating System
  • 2. Data Storage In Android Shared Preferences:-Store private primitive data in key-value pairs. Internal Storage:-Store private data on the device memory. External Storage:-Store public data on the shared external storage. SQLite Databases:-Store structured data in a private database. Network Connection:-Store data on the web with your own network server.
  • 3. Shared Preferences Useful for storing and retrieving primitive data in key value pairs. Lightweight usage, such as saving application settings. Typical usage of SharedPreferences is for saving application such as username and password, auto login flag, remember-user flag etc.
  • 4. Shared Preferences Contd….. The shared preferences information is stored in an XML file on the device  Typically in/data/data/<Your Application’s package name>/shared_prefs SharedPreferences can be associated with the entire application, or to a specific activity. Use the getSharedPrefernces() method to get access to the preferences
  • 5. Shared Preferences Contd….. Example:  SharedPrefernces prefs = this.getSharedPrefernces(‘myPrefs, MODE_PRIVATE’) If the preferences XML file exist, it is opened, otherwise it is created. To Control access permission to the file:  MODE_PRIVATE:private only to the application  MODE_WORLD_READABLE:all application can read XML file  MODE_WORLD_WRITABLE:all application can write XML file
  • 6. Shared Preferences Contd….. To add Shared preferences, first an editor object is needed  Editor prefsEditor = prefs.edit(); Then,use the put() method to add the key-value pairs  prefsEditor.putString(“username”,”D-Link”);  prefsEditor.putString(“password”,”vlsi#1@2”);  prefsEditor.putint(“times-login”,1);  prefsEditor.commit();
  • 7. Shared Preferences Contd….. To retrieve shared preferences data:  String username = prefsEditor.getString(“username”.” ”);  String password = prefsEditor.getString(“password”.” ”); If you are using SharedPrefernces for specific activity, then use getPreferences() method  No need to specify the name of the preferences file
  • 9. Internal Storage Android can save files directly to the device internal storage. These files are private to the application and will be removed if you uninstall the application. We can create a file using openFileOutput() with parameter as file name and the operating mode. Generally not recommended to use files.
  • 10. Internal Storage Contd…. Similarly, we can open the file using openFileInput() passing the parameter as the filename with extension. File are use to store large amount of data Use I/O interfaces provided by java.io.* libraries to read/write files. Only local files can be accessed.
  • 11. File Operation(Read) Use context.openFileInput(string name) to open a private input file stream related to a program. Throw FileNotFoundException when file does not exist. Syntax:- fileinputStram.in=this.openfileinput(“xyz.txt”) . . . . . In.close()://Close input stream
  • 12. File Operation (Write) Use context.openFileOutput(string name,int mode ) to open a private output file stream related to a program. The file will be created if it does not exist. Output stream can be opened in append mode, which means new data will be appended to end of the file. String mystring=“Hello World”
  • 13. File Operation (write) Contd…. Syntax:- FileOutputStream outfile = this.openFileOutput(“myfile.txt”,MODE_APPEND) //Open and Write in”myfile.txt”,using append mode. Outfile.write(mystring.getBytes()); Outfile.close();//close output stream
  • 14. External Storage Every Android-compatible device supports a shared “external storage” that you can use to save files  Removable storage media (such as an SD card)  Internal (non-removable) storage File saved to the external storage are world readable and can be modified by the user when they enable USB mass storage to transfer files on computer. These files are private to the application and will be removed when the application is uninstalled.
  • 15. External Storage Continue Must check whether external storage is available first by calling getExternalStorageState()  Also check whether it allows read/write before reading/writing on it getExternalFilesDir() takes a parameter such as DIRECTORY_MUSIC,DIRECTORY_RINGTONE etc,to open specific type of subdirectories. For public shared directories,use getExternalStoragePublicDirectory()
  • 16. External Storage Contd….. For cache files,use getExternalCacheDir() All these are applicable for API level 8 or above For API level 7 or below ,use the method;  getExternalStorageDirectory()  Private files stored in//Android/data/<package_name>/files/  Cache files stored in//Android/data/<package_name>/cache/
  • 18. SQLite Databases android.database.sqlite Contains the SQLite database management classes that an application would use to manage its own private database. android.database.sqlite.SQLiteDatabase Contains the methods for: creating, opening, closing, inserting, updating, deleting and quering an SQLite database.
  • 19. android.database.sqlite - Classes  SQLiteCloseable - An object created from a SQLiteDatabase that can be closed.  SQLiteCursor - A Cursor implementation that exposes results from a query on a SQLiteDatabase.  SQLiteDatabase - Exposes methods to manage a SQLite database.  SQLiteOpenHelper - A helper class to manage database creation and version management.  SQLiteProgram - A base class for compiled SQLite programs.  SQLiteQuery - A SQLite program that represents a query that reads the resulting rows into a CursorWindow.  SQLiteQueryBuilder - a convenience class that helps build SQL queries to be sent to SQLiteDatabase objects.  SQLiteStatement - A pre-compiled statement against a SQLiteDatabase that can be reused.
  • 20. OpenOrCreateDatabase This method will open an existing database or create one in the application data area  import android.database.sqlite.SQLiteDatabase; SQLiteDatabase myDatabase; myDatabase = openOrCreateDatabase ("my_sqlite_database.db" , SQLiteDatabase.CREATE_IF_NECESSARY , null);
  • 21. Creating Tables Create a static string containing the SQLite CREATE statement, use the execSQL( ) method to execute it.  String createAuthor = "CREAT TABLE authors ( id INTEGER PRIMARY KEY AUTOINCREMENT, fname TEXT, lname TEXT); myDatabase.execSQL(createAuthor);
  • 22. insert( ), delete( ) long insert(String table, String nullColumnHack, ContentValues values) import android.content.ContentValues; ContentValues values = new ContentValues( ); values.put("firstname" , "J.K."); values.put("lastname" , "Rowling"); long newAuthorID = myDatabase.insert("tbl_authors" , "" , values); int delete(String table, String whereClause, String[] whereArgs) public void deleteBook(Integer bookId) { myDatabase.delete("tbl_books" , "id=?" , new String[ ] { bookId.toString( ) } ) ; }
  • 23. Update() int update(String table, ContentValues values, String whereClause, String[ ] whereArgs) public void updateBookTitle(Integer bookId, String newTitle) { ContentValues values = new ContentValues(); values.put("title" , newTitle); myDatabase.update("tbl_books" , values , "id=?" , new String[ ] {bookId.toString() } ); }
  • 26. Cloud Storage  Online file storage centres or cloud storage providers allow you to safely upload your files to the Internet.
  • 27. Cloud Storage Contd….. There are various providers of cloud storage Examples: Apple iCloud(Gives 5GB of free storage ) Dropbox(Gives 2GB of free storage ) Google Drive(Gives 15GB of free storage ) Amazon Cloud Drive(Gives 5GB of free storage Microsoft SkyDrive(Gives 7GB of free storage )