SlideShare une entreprise Scribd logo
1  sur  7
Télécharger pour lire hors ligne
CS425 - Web and Mobile Software Engineering
Dr. Lilia Sfaxi
27 avril 2017
Storage
Android Lab 04


STORAGE DR. LILIA SFAXI !1
MedTech
I. Storage in Android
There are several options to store persistent data in Android. The choice of the ideal solution
depends on the specific needs of the users:
• Is the data private or accessible to other applications?
• How much space is required?
• Must the data be structures, semi-structured or not structured?
The storage options we present in this lab are the following:
1. Shared Preferences
It is a general framework that enables to save and extract key-value pairs of primitive type. It
enables to store and retrieve boolean, float, integer, long and string data.
Typically, the Shared Preferences are used to save the preferences of the users, such as the
ring.
2. Internal Storage
It is possible to use the internal storage of the device to save files. By default, those files are
private (inaccessible to other applications). When the application is deleted, these files are too.
3. External Storage
All Android compatible devices support external storage, that can be an SD card, or an
internal non-removable space.
Saved files in an external storage are accessible to all applications, in read-only mode. They
can be modified by the user if the « USB mass storage » is activated to transfer the files to a
computer.
4. SQLite Database
Android provides a total support for SQLite DBMS. SQLite is a software library
implementing a SQL database engine with zero-configuration, very light and without
external dependencies.
All databases created in an application are accessible by name from everywhere in this
application, but not from the outside of the application.
A recommended method to create a SQLite database is to use a sub-class of
SQLiteOpenHelper, a helper class that facilitates the creation and handling of SQLite
databases.
STORAGE DR. LILIA SFAXI !2
II. Exercise 1: Shared Preferences
1. Objective
The goal of this first part is to create a simple application to store some data in the Shared
Preferences. The graphical interface will be as follows:
2. Implementation
To read an object from Shared Preferences, use one of the following methods:
• getSharedPreferences: to use several preference files defined by name.
• getPreferences: to use a single preference file, without defining a file name.
To add values:
• Call edit() to get a SharedPreferences.Editor
• Add values with methods such as: putBoolean() and putString()
• Validate these values with commit()
To read values, use getBoolean(), getString(),…
The obtained code looks like the following:
STORAGE DR. LILIA SFAXI !3
Activity 1: Create a project called Lab4, enabling to save and
read data in the Shared Preferences.
III. Exercise 2: Internal and External Storage
1. Objective
The main objective of this part is to create a simple application to store some data in internal
and external files. The interface will look like the following:
STORAGE DR. LILIA SFAXI !4
1 2
2. Internal Storage
To read and write in a file internal to the application, use the Java primitives FileInputStream
and FileOutputStream. When writing data, it is mandatory to specify one (or many) operational
mode(s). These modes can be combined using | operator.
• MODE_PRIVATE : The file is accessible only for the application that created it.
• MODE_WORLD_READABLE : The file is accessible by other applications in read-
only.
• MODE_WORLD_WRITEABLE : The file is writable by other applications.
• MODE_APPEND : If the file already exists, the data is appended at the end.
Here are some examples to read and write internal files.
To display the files of your application, open the Android Device Monitor (under Tools ->
Android) and choose File Explorer . You can find the file you created under le directory /data/
1
data/<your project package>/files
There is a bug in the API 24 devices preventing the file explorer to be displayed. Use devices with lower API
1
for testing.
STORAGE DR. LILIA SFAXI !5
Activity 2:
-Create the interface in a new activity, use an intent to go
from the preceding activity (Shared Preferences) to this one.
-Test the behaviour of the methods readInternal and
saveInternal and display the result in a toast, for now.
3. External Storage
To read or write files on the external storage, the application must have
READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions.
Before manipulating the storage, il must first verify its availability, using the method
getExternalStorageState.
Example of writing:
STORAGE DR. LILIA SFAXI !6
Example of reading:
Activity 3: Add the part where you write in an external file.
Change the layout in order to display the read text in the
corresponding TextArea (as showed in the interface above).
STORAGE DR. LILIA SFAXI !7

Contenu connexe

Tendances

Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Sunil kumar Mohanty
 
Types of Dependency Injection in Spring
Types of Dependency Injection in SpringTypes of Dependency Injection in Spring
Types of Dependency Injection in SpringSunil kumar Mohanty
 
java drag and drop and data transfer
java drag and drop and data transferjava drag and drop and data transfer
java drag and drop and data transferAnkit Desai
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkAkhil Mittal
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101Rich Helton
 
Ee java lab assignment 4
Ee java lab assignment 4Ee java lab assignment 4
Ee java lab assignment 4Kuntal Bhowmick
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questionsDhiraj Champawat
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for MainframersRich Helton
 
Different Types of Containers in Spring
Different Types of Containers in Spring Different Types of Containers in Spring
Different Types of Containers in Spring Sunil kumar Mohanty
 
Leverage Hibernate and Spring Features Together
Leverage Hibernate and Spring Features TogetherLeverage Hibernate and Spring Features Together
Leverage Hibernate and Spring Features TogetherEdureka!
 
10 reasons to choose the yii framework
10 reasons to choose the yii framework10 reasons to choose the yii framework
10 reasons to choose the yii frameworkjananya213
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionRichard Paul
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
Spring andspringboot training
Spring andspringboot trainingSpring andspringboot training
Spring andspringboot trainingMallikarjuna G D
 
.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14aminmesbahi
 
Spring essentials 2 Spring Series 02)
Spring essentials 2 Spring Series 02)Spring essentials 2 Spring Series 02)
Spring essentials 2 Spring Series 02)Heartin Jacob
 

Tendances (20)

Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample
 
yii1
yii1yii1
yii1
 
Types of Dependency Injection in Spring
Types of Dependency Injection in SpringTypes of Dependency Injection in Spring
Types of Dependency Injection in Spring
 
java drag and drop and data transfer
java drag and drop and data transferjava drag and drop and data transfer
java drag and drop and data transfer
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFramework
 
Pragmatic orchard
Pragmatic orchardPragmatic orchard
Pragmatic orchard
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
Ee java lab assignment 4
Ee java lab assignment 4Ee java lab assignment 4
Ee java lab assignment 4
 
02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions02 java spring-hibernate-experience-questions
02 java spring-hibernate-experience-questions
 
DJango
DJangoDJango
DJango
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
Different Types of Containers in Spring
Different Types of Containers in Spring Different Types of Containers in Spring
Different Types of Containers in Spring
 
Leverage Hibernate and Spring Features Together
Leverage Hibernate and Spring Features TogetherLeverage Hibernate and Spring Features Together
Leverage Hibernate and Spring Features Together
 
10 reasons to choose the yii framework
10 reasons to choose the yii framework10 reasons to choose the yii framework
10 reasons to choose the yii framework
 
Introduction to Spring's Dependency Injection
Introduction to Spring's Dependency InjectionIntroduction to Spring's Dependency Injection
Introduction to Spring's Dependency Injection
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
Spring andspringboot training
Spring andspringboot trainingSpring andspringboot training
Spring andspringboot training
 
CodeIgniter 101 Tutorial
CodeIgniter 101 TutorialCodeIgniter 101 Tutorial
CodeIgniter 101 Tutorial
 
.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14.NET Core, ASP.NET Core Course, Session 14
.NET Core, ASP.NET Core Course, Session 14
 
Spring essentials 2 Spring Series 02)
Spring essentials 2 Spring Series 02)Spring essentials 2 Spring Series 02)
Spring essentials 2 Spring Series 02)
 

Similaire à Android Storage Options Lab

Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behesteeHussain Behestee
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorageKrazy Koder
 
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdfMobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdfAbdullahMunir32
 
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.pdfAbdullahMunir32
 
Pertemuan 13 - Shared Preferences and Settings - Word - Salin.pdf
Pertemuan 13 - Shared Preferences and Settings - Word - Salin.pdfPertemuan 13 - Shared Preferences and Settings - Word - Salin.pdf
Pertemuan 13 - Shared Preferences and Settings - Word - Salin.pdfHendroGunawan8
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android Aakash Ugale
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptxFaezNasir
 
How to create android applications
How to create android applicationsHow to create android applications
How to create android applicationsTOPS Technologies
 
Scoped storage in android 10 all you need to know
Scoped storage in android 10  all you need to knowScoped storage in android 10  all you need to know
Scoped storage in android 10 all you need to knowRobertJackson147
 
Android project architecture
Android project architectureAndroid project architecture
Android project architectureSourabh Sahu
 
Introduction to Android Development and Security
Introduction to Android Development and SecurityIntroduction to Android Development and Security
Introduction to Android Development and SecurityKelwin Yang
 
iOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for BeginnersiOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for BeginnersRyanISI
 
Android local databases
Android local databasesAndroid local databases
Android local databasesFatimaYousif11
 
"Android" mobilių programėlių kūrimo įvadas #3
"Android" mobilių programėlių kūrimo įvadas #3"Android" mobilių programėlių kūrimo įvadas #3
"Android" mobilių programėlių kūrimo įvadas #3Tadas Jurelevičius
 

Similaire à Android Storage Options Lab (20)

Android session 4-behestee
Android session 4-behesteeAndroid session 4-behestee
Android session 4-behestee
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
Memory management
Memory managementMemory management
Memory management
 
Storage 8
Storage   8Storage   8
Storage 8
 
Android-data storage in android-chapter21
Android-data storage in android-chapter21Android-data storage in android-chapter21
Android-data storage in android-chapter21
 
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdfMobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdf
 
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
 
Pertemuan 13 - Shared Preferences and Settings - Word - Salin.pdf
Pertemuan 13 - Shared Preferences and Settings - Word - Salin.pdfPertemuan 13 - Shared Preferences and Settings - Word - Salin.pdf
Pertemuan 13 - Shared Preferences and Settings - Word - Salin.pdf
 
MA DHARSH.pptx
MA DHARSH.pptxMA DHARSH.pptx
MA DHARSH.pptx
 
Share preference
Share preferenceShare preference
Share preference
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx12_Data_Storage_Part_2.pptx
12_Data_Storage_Part_2.pptx
 
iOS Application Pentesting
iOS Application PentestingiOS Application Pentesting
iOS Application Pentesting
 
How to create android applications
How to create android applicationsHow to create android applications
How to create android applications
 
Scoped storage in android 10 all you need to know
Scoped storage in android 10  all you need to knowScoped storage in android 10  all you need to know
Scoped storage in android 10 all you need to know
 
Android project architecture
Android project architectureAndroid project architecture
Android project architecture
 
Introduction to Android Development and Security
Introduction to Android Development and SecurityIntroduction to Android Development and Security
Introduction to Android Development and Security
 
iOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for BeginnersiOS Application Penetration Testing for Beginners
iOS Application Penetration Testing for Beginners
 
Android local databases
Android local databasesAndroid local databases
Android local databases
 
"Android" mobilių programėlių kūrimo įvadas #3
"Android" mobilių programėlių kūrimo įvadas #3"Android" mobilių programėlių kūrimo įvadas #3
"Android" mobilių programėlių kūrimo įvadas #3
 

Plus de Lilia Sfaxi

chp1-Intro à l'urbanisation des SI.pdf
chp1-Intro à l'urbanisation des SI.pdfchp1-Intro à l'urbanisation des SI.pdf
chp1-Intro à l'urbanisation des SI.pdfLilia Sfaxi
 
Plan d'études_INSAT_2022_2023.pdf
Plan d'études_INSAT_2022_2023.pdfPlan d'études_INSAT_2022_2023.pdf
Plan d'études_INSAT_2022_2023.pdfLilia Sfaxi
 
Lab1-DB-Cassandra
Lab1-DB-CassandraLab1-DB-Cassandra
Lab1-DB-CassandraLilia Sfaxi
 
TP2-UML-Correction
TP2-UML-CorrectionTP2-UML-Correction
TP2-UML-CorrectionLilia Sfaxi
 
TP1-UML-Correction
TP1-UML-CorrectionTP1-UML-Correction
TP1-UML-CorrectionLilia Sfaxi
 
TP0-UML-Correction
TP0-UML-CorrectionTP0-UML-Correction
TP0-UML-CorrectionLilia Sfaxi
 
TD4-UML-Correction
TD4-UML-CorrectionTD4-UML-Correction
TD4-UML-CorrectionLilia Sfaxi
 
TD3-UML-Séquences
TD3-UML-SéquencesTD3-UML-Séquences
TD3-UML-SéquencesLilia Sfaxi
 
TD3-UML-Correction
TD3-UML-CorrectionTD3-UML-Correction
TD3-UML-CorrectionLilia Sfaxi
 
TD2 - UML - Correction
TD2 - UML - CorrectionTD2 - UML - Correction
TD2 - UML - CorrectionLilia Sfaxi
 
TD1-UML-correction
TD1-UML-correctionTD1-UML-correction
TD1-UML-correctionLilia Sfaxi
 
Android - Tp1 - installation et démarrage
Android - Tp1 -   installation et démarrageAndroid - Tp1 -   installation et démarrage
Android - Tp1 - installation et démarrageLilia Sfaxi
 
Android - Tp2 - Elements graphiques
Android - Tp2 - Elements graphiques Android - Tp2 - Elements graphiques
Android - Tp2 - Elements graphiques Lilia Sfaxi
 
Android - Tp3 - intents
Android - Tp3 -  intentsAndroid - Tp3 -  intents
Android - Tp3 - intentsLilia Sfaxi
 
Android - TPBonus - web services
Android - TPBonus - web servicesAndroid - TPBonus - web services
Android - TPBonus - web servicesLilia Sfaxi
 
Android - Tp4 - graphiques avancés
Android - Tp4 - graphiques avancésAndroid - Tp4 - graphiques avancés
Android - Tp4 - graphiques avancésLilia Sfaxi
 

Plus de Lilia Sfaxi (20)

chp1-Intro à l'urbanisation des SI.pdf
chp1-Intro à l'urbanisation des SI.pdfchp1-Intro à l'urbanisation des SI.pdf
chp1-Intro à l'urbanisation des SI.pdf
 
Plan d'études_INSAT_2022_2023.pdf
Plan d'études_INSAT_2022_2023.pdfPlan d'études_INSAT_2022_2023.pdf
Plan d'études_INSAT_2022_2023.pdf
 
Lab3-DB_Neo4j
Lab3-DB_Neo4jLab3-DB_Neo4j
Lab3-DB_Neo4j
 
Lab2-DB-Mongodb
Lab2-DB-MongodbLab2-DB-Mongodb
Lab2-DB-Mongodb
 
Lab1-DB-Cassandra
Lab1-DB-CassandraLab1-DB-Cassandra
Lab1-DB-Cassandra
 
TP2-UML-Correction
TP2-UML-CorrectionTP2-UML-Correction
TP2-UML-Correction
 
TP1-UML-Correction
TP1-UML-CorrectionTP1-UML-Correction
TP1-UML-Correction
 
TP0-UML-Correction
TP0-UML-CorrectionTP0-UML-Correction
TP0-UML-Correction
 
TD4-UML
TD4-UMLTD4-UML
TD4-UML
 
TD4-UML-Correction
TD4-UML-CorrectionTD4-UML-Correction
TD4-UML-Correction
 
TD3-UML-Séquences
TD3-UML-SéquencesTD3-UML-Séquences
TD3-UML-Séquences
 
TD3-UML-Correction
TD3-UML-CorrectionTD3-UML-Correction
TD3-UML-Correction
 
TD2 - UML - Correction
TD2 - UML - CorrectionTD2 - UML - Correction
TD2 - UML - Correction
 
TD1 - UML - DCU
TD1 - UML - DCUTD1 - UML - DCU
TD1 - UML - DCU
 
TD1-UML-correction
TD1-UML-correctionTD1-UML-correction
TD1-UML-correction
 
Android - Tp1 - installation et démarrage
Android - Tp1 -   installation et démarrageAndroid - Tp1 -   installation et démarrage
Android - Tp1 - installation et démarrage
 
Android - Tp2 - Elements graphiques
Android - Tp2 - Elements graphiques Android - Tp2 - Elements graphiques
Android - Tp2 - Elements graphiques
 
Android - Tp3 - intents
Android - Tp3 -  intentsAndroid - Tp3 -  intents
Android - Tp3 - intents
 
Android - TPBonus - web services
Android - TPBonus - web servicesAndroid - TPBonus - web services
Android - TPBonus - web services
 
Android - Tp4 - graphiques avancés
Android - Tp4 - graphiques avancésAndroid - Tp4 - graphiques avancés
Android - Tp4 - graphiques avancés
 

Dernier

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...amber724300
 

Dernier (20)

Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
 

Android Storage Options Lab

  • 1. CS425 - Web and Mobile Software Engineering Dr. Lilia Sfaxi 27 avril 2017 Storage Android Lab 04 
 STORAGE DR. LILIA SFAXI !1 MedTech
  • 2. I. Storage in Android There are several options to store persistent data in Android. The choice of the ideal solution depends on the specific needs of the users: • Is the data private or accessible to other applications? • How much space is required? • Must the data be structures, semi-structured or not structured? The storage options we present in this lab are the following: 1. Shared Preferences It is a general framework that enables to save and extract key-value pairs of primitive type. It enables to store and retrieve boolean, float, integer, long and string data. Typically, the Shared Preferences are used to save the preferences of the users, such as the ring. 2. Internal Storage It is possible to use the internal storage of the device to save files. By default, those files are private (inaccessible to other applications). When the application is deleted, these files are too. 3. External Storage All Android compatible devices support external storage, that can be an SD card, or an internal non-removable space. Saved files in an external storage are accessible to all applications, in read-only mode. They can be modified by the user if the « USB mass storage » is activated to transfer the files to a computer. 4. SQLite Database Android provides a total support for SQLite DBMS. SQLite is a software library implementing a SQL database engine with zero-configuration, very light and without external dependencies. All databases created in an application are accessible by name from everywhere in this application, but not from the outside of the application. A recommended method to create a SQLite database is to use a sub-class of SQLiteOpenHelper, a helper class that facilitates the creation and handling of SQLite databases. STORAGE DR. LILIA SFAXI !2
  • 3. II. Exercise 1: Shared Preferences 1. Objective The goal of this first part is to create a simple application to store some data in the Shared Preferences. The graphical interface will be as follows: 2. Implementation To read an object from Shared Preferences, use one of the following methods: • getSharedPreferences: to use several preference files defined by name. • getPreferences: to use a single preference file, without defining a file name. To add values: • Call edit() to get a SharedPreferences.Editor • Add values with methods such as: putBoolean() and putString() • Validate these values with commit() To read values, use getBoolean(), getString(),… The obtained code looks like the following: STORAGE DR. LILIA SFAXI !3
  • 4. Activity 1: Create a project called Lab4, enabling to save and read data in the Shared Preferences. III. Exercise 2: Internal and External Storage 1. Objective The main objective of this part is to create a simple application to store some data in internal and external files. The interface will look like the following: STORAGE DR. LILIA SFAXI !4 1 2
  • 5. 2. Internal Storage To read and write in a file internal to the application, use the Java primitives FileInputStream and FileOutputStream. When writing data, it is mandatory to specify one (or many) operational mode(s). These modes can be combined using | operator. • MODE_PRIVATE : The file is accessible only for the application that created it. • MODE_WORLD_READABLE : The file is accessible by other applications in read- only. • MODE_WORLD_WRITEABLE : The file is writable by other applications. • MODE_APPEND : If the file already exists, the data is appended at the end. Here are some examples to read and write internal files. To display the files of your application, open the Android Device Monitor (under Tools -> Android) and choose File Explorer . You can find the file you created under le directory /data/ 1 data/<your project package>/files There is a bug in the API 24 devices preventing the file explorer to be displayed. Use devices with lower API 1 for testing. STORAGE DR. LILIA SFAXI !5
  • 6. Activity 2: -Create the interface in a new activity, use an intent to go from the preceding activity (Shared Preferences) to this one. -Test the behaviour of the methods readInternal and saveInternal and display the result in a toast, for now. 3. External Storage To read or write files on the external storage, the application must have READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions. Before manipulating the storage, il must first verify its availability, using the method getExternalStorageState. Example of writing: STORAGE DR. LILIA SFAXI !6
  • 7. Example of reading: Activity 3: Add the part where you write in an external file. Change the layout in order to display the read text in the corresponding TextArea (as showed in the interface above). STORAGE DR. LILIA SFAXI !7