SlideShare a Scribd company logo
PhoneGap: Local Storage
PhoneGap: Local Storage
•
–
–
•
•
•
PhoneGap: Local Storage
PhoneGap: Local Storage
–
PhoneGap: Local Storage
PhoneGap: Local Storage
localStorage
window.localStorage.setItem(“name”, “Ivano”);
var name = window.localStorage.getItem(“name”);
.key(0)
.getItem(“key”)
.setItem(“key”, “value”)
.removeItem(“key”)
.clear()


// simple class declaration
function Person(name, surname) {
this.name = name;
this.surname = surname;
}
// object creation
var user = new Person(„Ivano‟, „Malavolta‟);
// object serialization
window.localStorage.setItem(“user”, JSON.stringify(user));
// object retrieval
var current =
JSON.parse(window.localStorage.getItem(“user”));
if (window.localStorage.getItem(“user”)) {
// there is an object in user
} else {
// the user key does not have any value
}
var users = [...]; // array of Person objects
window.localStorage.setItem(“users”,
JSON.stringify(users));
var allUsers =
JSON.parse(window.localStorage.getItem(“users”));
var ivanos = [];
for(var i=0; i<allUsers.length; i++) {
if(allUsers[i].name == „Ivano‟)
ivanos.push(allUsers[i]);
}
var usersNumber =
JSON.parse(window.localStorage.getItem(“users“)).length;

PhoneGap: Local Storage
tx.executeSql("SELECT * FROM User“, [],
function(tx, result) {
// callback code
});
var db =
openDatabase(„Test', „1.0', „Test DB', 100000);
openDatabase(name, version, displayname, size);
db.changeVersion("1.0", "1.1");
db.transaction(queries, error, success);
PhoneGap: Local Storage
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS USER');
tx.executeSql('CREATE TABLE IF NOT EXISTS USER (id
unique, name, surname)');
tx.executeSql('INSERT INTO USER(id, name, surname)
VALUES (1, ?, ?)„, [“Ivano“, “Malavolta“],
success, error);
}
rows
...
tx.executeSql('INSERT INTO USER(id, name,surname) VALUES (5,
?, ?)„, [“Ivano“, “Malavolta“], success, error);
}
function success(tx, results) {
var affected = results.rowsAffected(); // 1
}
function error(err) {
// code for managing the error
}
length
item(index)
...
tx.executeSql(„SELECT * FROM USER„, [], success, error);
}
function success(tx, results) {
var size = results.rows.length;
for (var i=0; i<size; i++){
console.log(results.rows.item(i).name);
}
}
•
•
...
tx.executeSql(„SELECT * FROM USER„,[], success, error);
}
function error(err) {
console.log(err.code);
}
PhoneGap: Local Storage


PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
–
–
–
–
–
requestFileSystem(type, size, successCb, [errorCb])

window.requestFileSystem(
LocalFileSystem.PERSISTENT,
0,
onSuccess,
onError);
function onSuccess(fileSystem) {
console.log(fileSystem.name);
}
PhoneGap: Local Storage
window.resolveLocalFileSystemURI(
"file:///userImg.png", onSuccess, onError);
function onSuccess(fileEntry) {
console.log(fileEntry.name);
}
The real objects
Descriptor
Writing & Reading objects
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage
PhoneGap: Local Storage

PhoneGap: Local Storage
entry.file(win, fail);
function win(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log(evt.target.result);
};
reader.readAsText(file);
// reader.abort();
};
function fail(evt) {
console.log(error.code);
};
PhoneGap: Local Storage

append
PhoneGap: Local Storage
entry.createWriter(win, fail);
function win(writer) {
writer.onwrite = function(evt) {
console.log(“ok");
};
writer.write(“Ivano Malavolta");
};
function fail(evt) {
// error management
};
PhoneGap: Local Storage
var directoryReader = dirEntry.createReader();
directoryReader.readEntries(success, fail);
function success(entries) {
var i;
for (i=0; i<entries.length; i++) {
console.log(entries[i].name);
}
}
function fail(error) {
console.log(error.code);
}
window.requestFileSystem(window.PERSISTENT, 0, initFS, error);
function initFS(fs) {
fs.root.getFile(„log.txt', {}, win, error);
}
function win(fileEntry) {
fileEntry.file(read, error);
}
function read(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
console.log(this.result);
};
reader.readAsText(file);
}
function error(err) { console.log(err);}
PhoneGap: Local Storage

• 
•
• 
•
•
• 
• 
• 
• 
•
• 
• 
• 
• 
• 
•
• 
•
•

•






PhoneGap: Local Storage

More Related Content

What's hot (20)

PDF
HTML5 and CSS3 Refresher
Ivano Malavolta
 
PPTX
London XQuery Meetup: Querying the World (Web Scraping)
Dennis Knochenwefel
 
PDF
Юрий Буянов «Squeryl — ORM с человеческим лицом»
e-Legion
 
PDF
Rediscovering JavaScript: The Language Behind The Libraries
Simon Willison
 
PDF
The jQuery Divide
Rebecca Murphey
 
PDF
Javascript session june 2013 (iii) jquery json
abksharma
 
ODP
Introduction to jQuery
manugoel2003
 
PDF
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Luis Curo Salvatierra
 
PPTX
Oh, you’re the NY times guy
David Hayes
 
PDF
画像Hacks
Yusuke Wada
 
PDF
Crowdsourcing with Django
Simon Willison
 
PPTX
Jquery-overview
Isfand yar Khan
 
PDF
jQuery Essentials
Marc Grabanski
 
PDF
Command-Oriented Architecture
Luiz Messias
 
PPT
An Elephant of a Different Colour: Hack
Vic Metcalfe
 
PDF
Jqeury ajax plugins
Inbal Geffen
 
PPTX
jQuery
Jay Poojara
 
PDF
Game jump: frontend introduction #1
Sebastian Pożoga
 
PDF
Building Persona: federated and privacy-sensitive identity for the Web (Open ...
Francois Marier
 
PDF
Node.js - Demnächst auf einem Server in Ihrer Nähe
Ralph Winzinger
 
HTML5 and CSS3 Refresher
Ivano Malavolta
 
London XQuery Meetup: Querying the World (Web Scraping)
Dennis Knochenwefel
 
Юрий Буянов «Squeryl — ORM с человеческим лицом»
e-Legion
 
Rediscovering JavaScript: The Language Behind The Libraries
Simon Willison
 
The jQuery Divide
Rebecca Murphey
 
Javascript session june 2013 (iii) jquery json
abksharma
 
Introduction to jQuery
manugoel2003
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Luis Curo Salvatierra
 
Oh, you’re the NY times guy
David Hayes
 
画像Hacks
Yusuke Wada
 
Crowdsourcing with Django
Simon Willison
 
Jquery-overview
Isfand yar Khan
 
jQuery Essentials
Marc Grabanski
 
Command-Oriented Architecture
Luiz Messias
 
An Elephant of a Different Colour: Hack
Vic Metcalfe
 
Jqeury ajax plugins
Inbal Geffen
 
jQuery
Jay Poojara
 
Game jump: frontend introduction #1
Sebastian Pożoga
 
Building Persona: federated and privacy-sensitive identity for the Web (Open ...
Francois Marier
 
Node.js - Demnächst auf einem Server in Ihrer Nähe
Ralph Winzinger
 

Viewers also liked (20)

PDF
The Mobile ecosystem, Context & Strategies
Ivano Malavolta
 
PDF
Handlebars & Require JS
Ivano Malavolta
 
PDF
Backbone.js
Ivano Malavolta
 
PDF
Mobile geolocation and mapping
Ivano Malavolta
 
PDF
Apache Cordova APIs version 4.3.0
Ivano Malavolta
 
PDF
Mobile Apps Development: Technological strategies and Monetization
Ivano Malavolta
 
PDF
PhoneGap: Accessing Device Capabilities
Ivano Malavolta
 
PDF
Local data storage for mobile apps
Ivano Malavolta
 
PDF
Backbone JS for mobile apps
Ivano Malavolta
 
PDF
UI Design Patterns for Mobile Apps
Ivano Malavolta
 
PDF
Mobile Applications Development - Lecture 0 - Spring 2013
Ivano Malavolta
 
PDF
[2015/2016] Local data storage for web-based mobile apps
Ivano Malavolta
 
PDF
[2015/2016] Modern development paradigms
Ivano Malavolta
 
PDF
Mobile Applications Development - Lecture 0
Ivano Malavolta
 
PDF
Design patterns for mobile apps
Ivano Malavolta
 
PDF
UI design for mobile apps
Ivano Malavolta
 
PDF
Sitemaps & Wireframing
Ivano Malavolta
 
PDF
PhoneGap
Ivano Malavolta
 
PDF
Javascript and jQuery for Mobile
Ivano Malavolta
 
PDF
[2015/2016] AADL (Architecture Analysis and Design Language)
Ivano Malavolta
 
The Mobile ecosystem, Context & Strategies
Ivano Malavolta
 
Handlebars & Require JS
Ivano Malavolta
 
Backbone.js
Ivano Malavolta
 
Mobile geolocation and mapping
Ivano Malavolta
 
Apache Cordova APIs version 4.3.0
Ivano Malavolta
 
Mobile Apps Development: Technological strategies and Monetization
Ivano Malavolta
 
PhoneGap: Accessing Device Capabilities
Ivano Malavolta
 
Local data storage for mobile apps
Ivano Malavolta
 
Backbone JS for mobile apps
Ivano Malavolta
 
UI Design Patterns for Mobile Apps
Ivano Malavolta
 
Mobile Applications Development - Lecture 0 - Spring 2013
Ivano Malavolta
 
[2015/2016] Local data storage for web-based mobile apps
Ivano Malavolta
 
[2015/2016] Modern development paradigms
Ivano Malavolta
 
Mobile Applications Development - Lecture 0
Ivano Malavolta
 
Design patterns for mobile apps
Ivano Malavolta
 
UI design for mobile apps
Ivano Malavolta
 
Sitemaps & Wireframing
Ivano Malavolta
 
PhoneGap
Ivano Malavolta
 
Javascript and jQuery for Mobile
Ivano Malavolta
 
[2015/2016] AADL (Architecture Analysis and Design Language)
Ivano Malavolta
 
Ad

Similar to PhoneGap: Local Storage (20)

PPTX
Object oriented javascript
Shah Jalal
 
PPTX
Build your own entity with Drupal
Marco Vito Moscaritolo
 
PPTX
jQuery Data Manipulate API - A source code dissecting journey
Huiyi Yan
 
PDF
jQuery secrets
Bastian Feder
 
PDF
JS Level Up: Prototypes
Vernon Kesner
 
PDF
JQuery do dia-a-dia Gustavo Dutra
Tchelinux
 
PDF
jQuery - Introdução
Gustavo Dutra
 
PDF
jQuery secrets
Bastian Feder
 
PDF
Persisting Data on SQLite using Room
Nelson Glauber Leal
 
KEY
Backbone js
rstankov
 
PDF
Automatically Spotting Cross-language Relations
Federico Tomassetti
 
KEY
2012 oct-12 - java script inheritance
pedro.carvalho
 
PDF
Тройничок: Selenide для Web, Android и iOS
Andrei Solntsev
 
PPTX
Android - Memory leaks
Douglas Leandro Kleinkauf
 
PDF
Object-oriented Javascript
Daniel Ku
 
PDF
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
PDF
HTML5 APIs - Where no man has gone before! - Altran
Robert Nyman
 
PDF
Snapshot Testing @ CocoaheadsNL
Lars Lockefeer
 
PPTX
Get started with YUI
Adam Lu
 
Object oriented javascript
Shah Jalal
 
Build your own entity with Drupal
Marco Vito Moscaritolo
 
jQuery Data Manipulate API - A source code dissecting journey
Huiyi Yan
 
jQuery secrets
Bastian Feder
 
JS Level Up: Prototypes
Vernon Kesner
 
JQuery do dia-a-dia Gustavo Dutra
Tchelinux
 
jQuery - Introdução
Gustavo Dutra
 
jQuery secrets
Bastian Feder
 
Persisting Data on SQLite using Room
Nelson Glauber Leal
 
Backbone js
rstankov
 
Automatically Spotting Cross-language Relations
Federico Tomassetti
 
2012 oct-12 - java script inheritance
pedro.carvalho
 
Тройничок: Selenide для Web, Android и iOS
Andrei Solntsev
 
Android - Memory leaks
Douglas Leandro Kleinkauf
 
Object-oriented Javascript
Daniel Ku
 
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
HTML5 APIs - Where no man has gone before! - Altran
Robert Nyman
 
Snapshot Testing @ CocoaheadsNL
Lars Lockefeer
 
Get started with YUI
Adam Lu
 
Ad

More from Ivano Malavolta (20)

PDF
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
PDF
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Ivano Malavolta
 
PDF
The H2020 experience
Ivano Malavolta
 
PDF
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
Ivano Malavolta
 
PDF
Software sustainability and Green IT
Ivano Malavolta
 
PDF
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Ivano Malavolta
 
PDF
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
Ivano Malavolta
 
PDF
Collaborative Model-Driven Software Engineering: a Classification Framework a...
Ivano Malavolta
 
PDF
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Ivano Malavolta
 
PDF
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Ivano Malavolta
 
PDF
Modeling behaviour via UML state machines [Software Design] [Computer Science...
Ivano Malavolta
 
PDF
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Ivano Malavolta
 
PDF
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Ivano Malavolta
 
PDF
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Ivano Malavolta
 
PDF
Modeling and abstraction, software development process [Software Design] [Com...
Ivano Malavolta
 
PDF
[2017/2018] Agile development
Ivano Malavolta
 
PDF
Reconstructing microservice-based architectures
Ivano Malavolta
 
PDF
[2017/2018] AADL - Architecture Analysis and Design Language
Ivano Malavolta
 
PDF
[2017/2018] Architectural languages
Ivano Malavolta
 
PDF
[2017/2018] Introduction to Software Architecture
Ivano Malavolta
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Conducting Experiments on the Software Architecture of Robotic Systems (QRARS...
Ivano Malavolta
 
The H2020 experience
Ivano Malavolta
 
The Green Lab - Research cocktail @Vrije Universiteit Amsterdam (October 2020)
Ivano Malavolta
 
Software sustainability and Green IT
Ivano Malavolta
 
Navigation-aware and Personalized Prefetching of Network Requests in Android ...
Ivano Malavolta
 
How Maintainability Issues of Android Apps Evolve [ICSME 2018]
Ivano Malavolta
 
Collaborative Model-Driven Software Engineering: a Classification Framework a...
Ivano Malavolta
 
Experimenting on Mobile Apps Quality - a tale about Energy, Performance, and ...
Ivano Malavolta
 
Modeling objects interaction via UML sequence diagrams [Software Design] [Com...
Ivano Malavolta
 
Modeling behaviour via UML state machines [Software Design] [Computer Science...
Ivano Malavolta
 
Object-oriented design patterns in UML [Software Design] [Computer Science] [...
Ivano Malavolta
 
Structure modeling with UML [Software Design] [Computer Science] [Vrije Unive...
Ivano Malavolta
 
Requirements engineering with UML [Software Design] [Computer Science] [Vrije...
Ivano Malavolta
 
Modeling and abstraction, software development process [Software Design] [Com...
Ivano Malavolta
 
[2017/2018] Agile development
Ivano Malavolta
 
Reconstructing microservice-based architectures
Ivano Malavolta
 
[2017/2018] AADL - Architecture Analysis and Design Language
Ivano Malavolta
 
[2017/2018] Architectural languages
Ivano Malavolta
 
[2017/2018] Introduction to Software Architecture
Ivano Malavolta
 

Recently uploaded (20)

PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Per Axbom: The spectacular lies of maps
Nexer Digital
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
The Future of Artificial Intelligence (AI)
Mukul
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Per Axbom: The spectacular lies of maps
Nexer Digital
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 

PhoneGap: Local Storage