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

PDF
Jquery In Rails
PDF
Prototype & jQuery
PDF
DOM Scripting Toolkit - jQuery
DOC
PDF
Learning jQuery in 30 minutes
PDF
Coding website
KEY
JQuery In Rails
PPTX
webstudy jquery
Jquery In Rails
Prototype & jQuery
DOM Scripting Toolkit - jQuery
Learning jQuery in 30 minutes
Coding website
JQuery In Rails
webstudy jquery

What's hot (20)

PDF
HTML5 and CSS3 Refresher
PPTX
London XQuery Meetup: Querying the World (Web Scraping)
PDF
Юрий Буянов «Squeryl — ORM с человеческим лицом»
PDF
Rediscovering JavaScript: The Language Behind The Libraries
PDF
The jQuery Divide
PDF
Javascript session june 2013 (iii) jquery json
ODP
Introduction to jQuery
PDF
Desarrollo de módulos en Drupal e integración con dispositivos móviles
PPTX
Oh, you’re the NY times guy
PDF
画像Hacks
PDF
Crowdsourcing with Django
PPTX
Jquery-overview
PDF
jQuery Essentials
PDF
Command-Oriented Architecture
PPT
An Elephant of a Different Colour: Hack
PDF
Jqeury ajax plugins
PPTX
jQuery
PDF
Game jump: frontend introduction #1
PDF
Building Persona: federated and privacy-sensitive identity for the Web (Open ...
PDF
Node.js - Demnächst auf einem Server in Ihrer Nähe
HTML5 and CSS3 Refresher
London XQuery Meetup: Querying the World (Web Scraping)
Юрий Буянов «Squeryl — ORM с человеческим лицом»
Rediscovering JavaScript: The Language Behind The Libraries
The jQuery Divide
Javascript session june 2013 (iii) jquery json
Introduction to jQuery
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Oh, you’re the NY times guy
画像Hacks
Crowdsourcing with Django
Jquery-overview
jQuery Essentials
Command-Oriented Architecture
An Elephant of a Different Colour: Hack
Jqeury ajax plugins
jQuery
Game jump: frontend introduction #1
Building Persona: federated and privacy-sensitive identity for the Web (Open ...
Node.js - Demnächst auf einem Server in Ihrer Nähe
Ad

Viewers also liked (20)

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

Similar to PhoneGap: Local Storage (20)

PPTX
Object oriented javascript
PPTX
Build your own entity with Drupal
PPTX
jQuery Data Manipulate API - A source code dissecting journey
PDF
jQuery secrets
PDF
JS Level Up: Prototypes
PDF
JQuery do dia-a-dia Gustavo Dutra
PDF
jQuery - Introdução
PDF
jQuery secrets
PDF
Persisting Data on SQLite using Room
KEY
Backbone js
PDF
Automatically Spotting Cross-language Relations
KEY
2012 oct-12 - java script inheritance
PDF
Тройничок: Selenide для Web, Android и iOS
PPTX
Android - Memory leaks
PDF
Object-oriented Javascript
PDF
international PHP2011_Bastian Feder_jQuery's Secrets
PDF
HTML5 APIs - Where no man has gone before! - Altran
PDF
Snapshot Testing @ CocoaheadsNL
PPTX
Get started with YUI
Object oriented javascript
Build your own entity with Drupal
jQuery Data Manipulate API - A source code dissecting journey
jQuery secrets
JS Level Up: Prototypes
JQuery do dia-a-dia Gustavo Dutra
jQuery - Introdução
jQuery secrets
Persisting Data on SQLite using Room
Backbone js
Automatically Spotting Cross-language Relations
2012 oct-12 - java script inheritance
Тройничок: Selenide для Web, Android и iOS
Android - Memory leaks
Object-oriented Javascript
international PHP2011_Bastian Feder_jQuery's Secrets
HTML5 APIs - Where no man has gone before! - Altran
Snapshot Testing @ CocoaheadsNL
Get started with YUI

More from Ivano Malavolta (20)

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

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Approach and Philosophy of On baking technology
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Machine learning based COVID-19 study performance prediction
PPTX
1. Introduction to Computer Programming.pptx
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
August Patch Tuesday
PDF
Getting Started with Data Integration: FME Form 101
PPTX
Tartificialntelligence_presentation.pptx
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
Unlocking AI with Model Context Protocol (MCP)
Encapsulation_ Review paper, used for researhc scholars
SOPHOS-XG Firewall Administrator PPT.pptx
Approach and Philosophy of On baking technology
A comparative study of natural language inference in Swahili using monolingua...
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Machine learning based COVID-19 study performance prediction
1. Introduction to Computer Programming.pptx
cloud_computing_Infrastucture_as_cloud_p
Mobile App Security Testing_ A Comprehensive Guide.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
August Patch Tuesday
Getting Started with Data Integration: FME Form 101
Tartificialntelligence_presentation.pptx
TLE Review Electricity (Electricity).pptx
Assigned Numbers - 2025 - Bluetooth® Document
Advanced methodologies resolving dimensionality complications for autism neur...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectral efficient network and resource selection model in 5G networks

PhoneGap: Local Storage