SlideShare a Scribd company logo
Slide 1 of 19© People Strategists www.peoplestrategists.com
Data Storage in Android
Slide 2 of 19© People Strategists www.peoplestrategists.com Slide 2 of 57© People Strategists www.peoplestrategists.com
Data Storage in Android
 Preferences
 Files
 SQLite
 Network
Slide 3 of 19© People Strategists www.peoplestrategists.com Slide 3 of 57© People Strategists www.peoplestrategists.com
Slide 4 of 19© People Strategists www.peoplestrategists.com
Preference
A way of data persistence in Android that stores data in form of
key value pair like user specific setting, endpoint url, the
security access token etc.
Android stores shared preference settings
as XML file under:-
data/data/packagename/shared_prefs/
packagename_preferences.xml.
Slide 5 of 19© People Strategists www.peoplestrategists.com
Preference
once you uninstall the
application
once you clear
application data (through
Settings)
The data is lost when you perform any one following task:-
Slide 6 of 19© People Strategists www.peoplestrategists.com
Commonly used Shared Preferences
 ListPreference
 CheckBoxPreference
 EditTextPreference
Slide 7 of 19© People Strategists www.peoplestrategists.com
Preference
Creating preferences:-
The Preferences Activity screen is defined in the preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key=“pref_screen“….>
<CheckBoxPreference
android:key=“checkbox_pref“…. />
<ListPreference
android:key=“list_pref“…./>
<EditTextPreference
android:key=“edit_pref”…./>
</PreferenceScreen>
Slide 8 of 19© People Strategists www.peoplestrategists.com
Create the Preferences Activity
public class AppPreferences extends PreferenceActivity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref);
}
}
Preference
Slide 9 of 19© People Strategists www.peoplestrategists.com
Preference
To read the preferences values
SharedPreferences sp =
PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String strUserName = sp.getString("username", “ABC");
boolean bAppUpdates = sp.getBoolean("applicationUpdates",false);
String downloadType = sp.getString("downloadType","1");
Slide 10 of 19© People Strategists www.peoplestrategists.com Slide 10 of 57© People Strategists www.peoplestrategists.com
Slide 11 of 19© People Strategists www.peoplestrategists.com
Internal storage
 It is private to your application and other applications
cannot access them (nor can the user)
 When the app uninstalls, these files are removed.
External storage
 External storage such as SD card can also store application data.
 There's no security enforced upon files you save to the external
storage.
 All applications can read and write files placed on the external
storage and the user can remove them for this they need Read
and Write permission.
Internal & External
Storage
Slide 12 of 19© People Strategists www.peoplestrategists.com
SQLite DB
SQLite is an Open Source database which supports standard
relational database features like SQL syntax, transaction etc.
It is embedded into every Android
device.
Database is by default saved in the
directory
DATA/data/APP_NAME/databases/FILENA
ME.
Slide 13 of 19© People Strategists www.peoplestrategists.com
SQLite DB
Necessary classes for working with databases:-
 SQLiteHelper
 SQLiteDataBase
 Cursor
Slide 14 of 19© People Strategists www.peoplestrategists.com
Content Provider
Slide 15 of 19© People Strategists www.peoplestrategists.com Slide 15 of 57© People Strategists www.peoplestrategists.com
Content Provider
An Android component that supplies data from one app to another on
request.
A content provider can use different ways to store its data and the data can be
stored in a database, infiles, or even over a network.
Slide 16 of 19© People Strategists www.peoplestrategists.com Slide 16 of 57© People Strategists www.peoplestrategists.com
Content Provider
Slide 17 of 19© People Strategists www.peoplestrategists.com Slide 17 of 57© People Strategists www.peoplestrategists.com
Content Provider
Creating content provider
 Create a content provider class that extends the contentproviderbaseclass.
 Define your content provider uri address.
 Create your own database to keep the content.
 Implement content provider queries.
 Register your content provider in menifest file.
Slide 18 of 19© People Strategists www.peoplestrategists.com Slide 18 of 57© People Strategists www.peoplestrategists.com
Demo
Security and Packages
Slide 19 of 19© People Strategists www.peoplestrategists.com Slide 19 of 57© People Strategists www.peoplestrategists.com
Demo
Talking to the Server

More Related Content

Similar to Android - Day 2 (20)

MySQL Enterprise Monitor
MySQL Enterprise MonitorMySQL Enterprise Monitor
MySQL Enterprise Monitor
Mark Swarbrick
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx
FaezNasir
 
Securing Your Mobile Backend featuring Forrester Research inc - Combine API B...
Securing Your Mobile Backend featuring Forrester Research inc - Combine API B...Securing Your Mobile Backend featuring Forrester Research inc - Combine API B...
Securing Your Mobile Backend featuring Forrester Research inc - Combine API B...
CA API Management
 
Security Quick Tour
Security Quick TourSecurity Quick Tour
Security Quick Tour
Active Base
 
Introduction to Big Data & Hadoop
Introduction to Big Data & Hadoop Introduction to Big Data & Hadoop
Introduction to Big Data & Hadoop
iACT Global
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Edureka!
 
Chap1-Introduction to database systems.ppt
Chap1-Introduction to database systems.pptChap1-Introduction to database systems.ppt
Chap1-Introduction to database systems.ppt
LisaMalar
 
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
 
Tk2323 lecture 7 data storage
Tk2323 lecture 7   data storageTk2323 lecture 7   data storage
Tk2323 lecture 7 data storage
MengChun Lam
 
DBMS Part1.pptx
DBMS Part1.pptxDBMS Part1.pptx
DBMS Part1.pptx
Prof. Dr. K. Adisesha
 
DBMS.pptx
DBMS.pptxDBMS.pptx
DBMS.pptx
Prof. Dr. K. Adisesha
 
Chapte sdfbjsvfjsb shdvgsfjsdhvshyjhscdgppt
Chapte sdfbjsvfjsb shdvgsfjsdhvshyjhscdgpptChapte sdfbjsvfjsb shdvgsfjsdhvshyjhscdgppt
Chapte sdfbjsvfjsb shdvgsfjsdhvshyjhscdgppt
ridmoon40318
 
Informatica PowerCenter : Agile Data Integration Tool
Informatica PowerCenter : Agile Data Integration ToolInformatica PowerCenter : Agile Data Integration Tool
Informatica PowerCenter : Agile Data Integration Tool
Edureka!
 
Database System Concepts and Architecture.ppt
Database System Concepts and Architecture.pptDatabase System Concepts and Architecture.ppt
Database System Concepts and Architecture.ppt
MANASINANDKISHORDEOR
 
Lesson02 database system architecture
Lesson02 database system architectureLesson02 database system architecture
Lesson02 database system architecture
Muhammad Sikandar Mustafa
 
SoftAge eDMS
SoftAge eDMSSoftAge eDMS
SoftAge eDMS
SoftAge Information Technology Limited
 
What's Next with Government Big Data
What's Next with Government Big Data What's Next with Government Big Data
What's Next with Government Big Data
GovLoop
 
Seqrite Data Loss Prevention- Complete Protection from Data Theft and Data Loss
Seqrite Data Loss Prevention- Complete Protection from Data Theft and Data LossSeqrite Data Loss Prevention- Complete Protection from Data Theft and Data Loss
Seqrite Data Loss Prevention- Complete Protection from Data Theft and Data Loss
Quick Heal Technologies Ltd.
 
1. What are some risks, threats, and vulnerabilities commonly foun.docx
1. What are some risks, threats, and vulnerabilities commonly foun.docx1. What are some risks, threats, and vulnerabilities commonly foun.docx
1. What are some risks, threats, and vulnerabilities commonly foun.docx
elliotkimberlee
 
Informatica Capabilities As An ETL Tool
Informatica Capabilities As An ETL ToolInformatica Capabilities As An ETL Tool
Informatica Capabilities As An ETL Tool
Edureka!
 
MySQL Enterprise Monitor
MySQL Enterprise MonitorMySQL Enterprise Monitor
MySQL Enterprise Monitor
Mark Swarbrick
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx
FaezNasir
 
Securing Your Mobile Backend featuring Forrester Research inc - Combine API B...
Securing Your Mobile Backend featuring Forrester Research inc - Combine API B...Securing Your Mobile Backend featuring Forrester Research inc - Combine API B...
Securing Your Mobile Backend featuring Forrester Research inc - Combine API B...
CA API Management
 
Security Quick Tour
Security Quick TourSecurity Quick Tour
Security Quick Tour
Active Base
 
Introduction to Big Data & Hadoop
Introduction to Big Data & Hadoop Introduction to Big Data & Hadoop
Introduction to Big Data & Hadoop
iACT Global
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Edureka!
 
Chap1-Introduction to database systems.ppt
Chap1-Introduction to database systems.pptChap1-Introduction to database systems.ppt
Chap1-Introduction to database systems.ppt
LisaMalar
 
Tk2323 lecture 7 data storage
Tk2323 lecture 7   data storageTk2323 lecture 7   data storage
Tk2323 lecture 7 data storage
MengChun Lam
 
Chapte sdfbjsvfjsb shdvgsfjsdhvshyjhscdgppt
Chapte sdfbjsvfjsb shdvgsfjsdhvshyjhscdgpptChapte sdfbjsvfjsb shdvgsfjsdhvshyjhscdgppt
Chapte sdfbjsvfjsb shdvgsfjsdhvshyjhscdgppt
ridmoon40318
 
Informatica PowerCenter : Agile Data Integration Tool
Informatica PowerCenter : Agile Data Integration ToolInformatica PowerCenter : Agile Data Integration Tool
Informatica PowerCenter : Agile Data Integration Tool
Edureka!
 
Database System Concepts and Architecture.ppt
Database System Concepts and Architecture.pptDatabase System Concepts and Architecture.ppt
Database System Concepts and Architecture.ppt
MANASINANDKISHORDEOR
 
What's Next with Government Big Data
What's Next with Government Big Data What's Next with Government Big Data
What's Next with Government Big Data
GovLoop
 
Seqrite Data Loss Prevention- Complete Protection from Data Theft and Data Loss
Seqrite Data Loss Prevention- Complete Protection from Data Theft and Data LossSeqrite Data Loss Prevention- Complete Protection from Data Theft and Data Loss
Seqrite Data Loss Prevention- Complete Protection from Data Theft and Data Loss
Quick Heal Technologies Ltd.
 
1. What are some risks, threats, and vulnerabilities commonly foun.docx
1. What are some risks, threats, and vulnerabilities commonly foun.docx1. What are some risks, threats, and vulnerabilities commonly foun.docx
1. What are some risks, threats, and vulnerabilities commonly foun.docx
elliotkimberlee
 
Informatica Capabilities As An ETL Tool
Informatica Capabilities As An ETL ToolInformatica Capabilities As An ETL Tool
Informatica Capabilities As An ETL Tool
Edureka!
 

More from People Strategists (20)

Overview of web services
Overview of web servicesOverview of web services
Overview of web services
People Strategists
 
Spring Framework - III
Spring Framework - IIISpring Framework - III
Spring Framework - III
People Strategists
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
People Strategists
 
Spring Framework -I
Spring Framework -ISpring Framework -I
Spring Framework -I
People Strategists
 
Hibernate II
Hibernate IIHibernate II
Hibernate II
People Strategists
 
Hibernate III
Hibernate IIIHibernate III
Hibernate III
People Strategists
 
Hibernate I
Hibernate IHibernate I
Hibernate I
People Strategists
 
Identifing Listeners and Filters
Identifing Listeners and FiltersIdentifing Listeners and Filters
Identifing Listeners and Filters
People Strategists
 
Exploring Maven SVN GIT
Exploring Maven SVN GITExploring Maven SVN GIT
Exploring Maven SVN GIT
People Strategists
 
Agile Dev. II
Agile Dev. IIAgile Dev. II
Agile Dev. II
People Strategists
 
Agile Dev. I
Agile Dev. IAgile Dev. I
Agile Dev. I
People Strategists
 
Working with Servlets
Working with ServletsWorking with Servlets
Working with Servlets
People Strategists
 
Overview of JEE Technology
Overview of JEE TechnologyOverview of JEE Technology
Overview of JEE Technology
People Strategists
 
JSP Technology II
JSP Technology IIJSP Technology II
JSP Technology II
People Strategists
 
XML Schemas
XML SchemasXML Schemas
XML Schemas
People Strategists
 
JSON and XML
JSON and XMLJSON and XML
JSON and XML
People Strategists
 
Ajax and Jquery
Ajax and JqueryAjax and Jquery
Ajax and Jquery
People Strategists
 
CSS
CSSCSS
CSS
People Strategists
 
HTML/HTML5
HTML/HTML5HTML/HTML5
HTML/HTML5
People Strategists
 
JDBC
JDBCJDBC
JDBC
People Strategists
 

Recently uploaded (20)

How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul Shares 5 Steps to Implement AI Agents for Maximum Business Efficien...
Noah Loul
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 

Android - Day 2

  • 1. Slide 1 of 19© People Strategists www.peoplestrategists.com Data Storage in Android
  • 2. Slide 2 of 19© People Strategists www.peoplestrategists.com Slide 2 of 57© People Strategists www.peoplestrategists.com Data Storage in Android  Preferences  Files  SQLite  Network
  • 3. Slide 3 of 19© People Strategists www.peoplestrategists.com Slide 3 of 57© People Strategists www.peoplestrategists.com
  • 4. Slide 4 of 19© People Strategists www.peoplestrategists.com Preference A way of data persistence in Android that stores data in form of key value pair like user specific setting, endpoint url, the security access token etc. Android stores shared preference settings as XML file under:- data/data/packagename/shared_prefs/ packagename_preferences.xml.
  • 5. Slide 5 of 19© People Strategists www.peoplestrategists.com Preference once you uninstall the application once you clear application data (through Settings) The data is lost when you perform any one following task:-
  • 6. Slide 6 of 19© People Strategists www.peoplestrategists.com Commonly used Shared Preferences  ListPreference  CheckBoxPreference  EditTextPreference
  • 7. Slide 7 of 19© People Strategists www.peoplestrategists.com Preference Creating preferences:- The Preferences Activity screen is defined in the preferences.xml <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:key=“pref_screen“….> <CheckBoxPreference android:key=“checkbox_pref“…. /> <ListPreference android:key=“list_pref“…./> <EditTextPreference android:key=“edit_pref”…./> </PreferenceScreen>
  • 8. Slide 8 of 19© People Strategists www.peoplestrategists.com Create the Preferences Activity public class AppPreferences extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref); } } Preference
  • 9. Slide 9 of 19© People Strategists www.peoplestrategists.com Preference To read the preferences values SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); String strUserName = sp.getString("username", “ABC"); boolean bAppUpdates = sp.getBoolean("applicationUpdates",false); String downloadType = sp.getString("downloadType","1");
  • 10. Slide 10 of 19© People Strategists www.peoplestrategists.com Slide 10 of 57© People Strategists www.peoplestrategists.com
  • 11. Slide 11 of 19© People Strategists www.peoplestrategists.com Internal storage  It is private to your application and other applications cannot access them (nor can the user)  When the app uninstalls, these files are removed. External storage  External storage such as SD card can also store application data.  There's no security enforced upon files you save to the external storage.  All applications can read and write files placed on the external storage and the user can remove them for this they need Read and Write permission. Internal & External Storage
  • 12. Slide 12 of 19© People Strategists www.peoplestrategists.com SQLite DB SQLite is an Open Source database which supports standard relational database features like SQL syntax, transaction etc. It is embedded into every Android device. Database is by default saved in the directory DATA/data/APP_NAME/databases/FILENA ME.
  • 13. Slide 13 of 19© People Strategists www.peoplestrategists.com SQLite DB Necessary classes for working with databases:-  SQLiteHelper  SQLiteDataBase  Cursor
  • 14. Slide 14 of 19© People Strategists www.peoplestrategists.com Content Provider
  • 15. Slide 15 of 19© People Strategists www.peoplestrategists.com Slide 15 of 57© People Strategists www.peoplestrategists.com Content Provider An Android component that supplies data from one app to another on request. A content provider can use different ways to store its data and the data can be stored in a database, infiles, or even over a network.
  • 16. Slide 16 of 19© People Strategists www.peoplestrategists.com Slide 16 of 57© People Strategists www.peoplestrategists.com Content Provider
  • 17. Slide 17 of 19© People Strategists www.peoplestrategists.com Slide 17 of 57© People Strategists www.peoplestrategists.com Content Provider Creating content provider  Create a content provider class that extends the contentproviderbaseclass.  Define your content provider uri address.  Create your own database to keep the content.  Implement content provider queries.  Register your content provider in menifest file.
  • 18. Slide 18 of 19© People Strategists www.peoplestrategists.com Slide 18 of 57© People Strategists www.peoplestrategists.com Demo Security and Packages
  • 19. Slide 19 of 19© People Strategists www.peoplestrategists.com Slide 19 of 57© People Strategists www.peoplestrategists.com Demo Talking to the Server