Phonegap Bridge – Storage CIS 136 Building Mobile Apps 1.

Slides:



Advertisements
Similar presentations
Bruce Scharlau, University of Aberdeen, 2012 Data storage options for mobiles Mobile Computing.
Advertisements

Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
My first computer: The Apple ][ It wanted to be programmed.
HTML5 Storage. Why Local Storage? Data accessed over the internet can never be as fast as accessing data locally Data accessed over internet not secure.
HTML5 Applications with ASP.NET Web Forms Stephen Walther Superexpert.com
 data/data-storage.html#pref data/data-storage.html#pref 
Programming with App Inventor Storing Data
Tracking & Login Data persistence User tracking.
HTML5 JavaScript Storage for Structured Data Andy Gup, Esri
Web Storage IDIA 619 Spring 2013 Bridget M. Blodgett.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Chapter 25 Utilizing Web Storage.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Martin Kruliš by Martin Kruliš (v1.0)1.
Tips for working with disconnected web mapping apps Andy Gup, Javier Abadia.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
NextGen Technology upgrade – Synerizip - Sandeep Kamble.
Phonegap Bridge – Telephony CIS 136 Building Mobile Apps 1.
Chapter 15: Using LINQ to Access Data in C# Programs.
State Management. What is State management Why State management ViewState QueryString Cookies.
CS378 - Mobile Computing Persistence. Saving State We have already seen saving app state into a Bundle on orientation changes or when an app is killed.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
HTML5. HTML5’s overall theme The browser as a rich application platform rich, cross-device user interfaces offline operation capability hardware access.
Moohanad Hassan Maedeh Pishvaei. Introduction Open Source Apache foundation project Relational DB: SQL Server CouchDB : JSON document-oriented DB (NoSQL)
Chapter 8 Cookies And Security JavaScript, Third Edition.
CHAP 6. USING THE HTML5 WEB STORAGE API.  Cookie - Are a built-in way of sending text values back and forth from server to client.  Servers can use.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
The Mobile CRM Conference 2015 September 14-15, 2015 in Boston, MA Take Your CRM to the Next Level.
Android Storage. There are several options for storage of data with Android We can put data into a preferences file. We can put data into a ‘normal’ file.
9 Persistence - SQLite CSNB544 Mobile Application Development Thanks to Utexas Austin.
ASP.NET State Management. Slide 2 Lecture Overview Client state management options Cookies Server state management options Application state Session state.
BlackBerry Persistent Storage Models Persistent Storage APIs and Record Management System.
Phonegap Bridge – Compass API CIS 136 Building Mobile Apps 1.
Creating Databases Local storage. join & split Classwork: show 1 table application. Share designs for oscars application. Adaptive select. Homework: [Catch.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
What's New in Kinetic Calendar 2.0 Jack Boespflug Kinetic Data.
Internet & World Wide Web How to Program, 5/e. 2.
Don’t Disconnect Me! The challenges of building offline-enabled web apps Matthias Oßwald,
Phonegap Bridge – Device, Network, Console, Geolocation API’s CIS 136 Building Mobile Apps 1.
Chapter 10 Database Management. Data and Information How are data and information related? p Fig Next processing data stored on disk Step.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
CS2550 Dr. Brian Durney. SOURCES  JavaScript: The Definitive Guide, by David Flanagan  Dive into HTML5, by Mark Pilgrim
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
Rich Internet Applications 9. HTML 5 and RIAs. HTML 5 Standard currently under development by W3C Aims to improve the language with support for the latest.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
JavaScript: Objects 1 © by Pearson Education, Inc. All Rights Reserved.
CSCI 6962: Server-side Design and Programming Shopping Carts and Databases.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Module 6: Administering Reporting Services. Overview Server Administration Performance and Reliability Monitoring Database Administration Security Administration.
POSTGRESQL 13 TH MARCH HISTORY DESIGNED BY MICHAEL STONEBRAKER ( ANDREW YU, JOLLY CHEN) AT UCLA (1999) COMMUNITY DEVELOPED 15 YEARS ACTIVE DEVELOPMENT.
ASP.NET Part II Dr. Awad Khalil Computer Science Department AUC.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Phonegap Bridge –Geolocation and Google maps CIS 136 Building Mobile Apps 1.
JQuery form submission CIS 136 Building Mobile Apps 1.
Developing for Chromecast Cast Companion Library & Custom Receiver Application.
Using HTML5 to Build Offline Applications Woody Pewitt Icenium
Phonegap Bridge – Device,Network, Vibration,Battery,Console CIS 136 Building Mobile Apps 1.
Mobile Application Development Data Storage. Android provides several options for you to save persistent application data. The solution you choose depends.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Web Storage and Cookies Cookies, Local and Session Storage SoftUni Team Technical Trainers Software University
REDCap Mobile Application
CIS 136 Building Mobile Apps
CIS 136 Building Mobile Apps
CIS 136 Building Mobile Apps
CIS 136 Building Mobile Apps
Developing a Model-View-Controller Component for Joomla Part 3
JavaScript & jQuery AJAX.
HTML5 and Local Storage.
PHP and JSON Topics Review JSON.
Presentation transcript:

Phonegap Bridge – Storage CIS 136 Building Mobile Apps 1

Storage Options 2

3  Many storage API’s  Local Storage  Web storage, simple storage, session storage  Based on key/value pairs  WebSQL (android, blackberry, iOS)  full-featured database tables accessed via SQL queries  IndexedDB (windows, blackberry)  more features than LocalStorage but fewer than WebSQL  Plug-in Based  File API - allows you to cache data on the local file system  Downloader - Downloads files to persistant Storage  SQLLite - more storage and more flexibility than the standard Web SQL database

Local Storage 4

5  App needs to store data that the user can retrieve later  Might store the data somewhere that can be accessed through some server  Facebook, Twitter etc.  requires an Internet connection

Local Storage 6  Reasons we might want to store some data locally:  The application is completely self contained and there is no interaction with other users, so all data can be stored locally  Need to store data locally for some specific functionality like a “Remember Me” feature  Skip unnecessary calls to a server by storing preference settings locally  Skip unnecessary calls to a server by caching other data locally  Sync online and offline data so that the user can continue using the application even when they are offline  Evernote Evernote

Local Storage 7  most basic storage option available  allows you to store up to 5MB of data  Unreliable  Data can get wiped out  use it where data loss is not an issue  never use it to store sensitive data since it can be easily accessed

Local Storage 8  a simple key-value system, using setters and getters localStorage.setItem('someSetting', 'off'); var someSetting = localStorage.getItem('someSetting');  can only store strings  to store an object or array, first convert it to a JSON string  to retrieve it later, decode JSON string back into an array or object

Local Storage 9  Permanent – localStorage() method  Data is saved even when app is closed  Temporary – sessionStorage() method  Data is not saved when app is closed

Methods 10 Works off of key/value pairs  Note: can serialize data using json.Stringify method  Set a key - Returns the name of the key at the specified position  var keyName = window.localStorage.key(0);  Set an item - Assigns a keyed item's value  window.localStorage.setItem("key", "value");  Get an item - Returns the item identified by the specified key  var value = window.localStorage.getItem("key");  Remove an item - Removes the item identified by the specified key  Window.localStorage.removeItem("key");  Clear - Removes all of the key/value pairs  Window.localStorage.clear();

11 // Wait for device API libraries to load document.addEventListener("deviceready", onDeviceReady, false); // device APIs are available function onDeviceReady() { window.localStorage.setItem(“hobby", “sailing"); var keyname = window.localStorage.key(0); // keyname is now = “hobby" var value = window.localStorage.getItem(“hobby"); // value is now = “sailing“ var value2 = window.localStorage.getItem(keyname); // value is now = “sailing" window.localStorage.removeItem(“hobby"); window.localStorage.setItem(“hobby2", “riding"); window.localStorage.clear(); // localStorage is now empty }

IndexedDB 12

IndexedDB 13  IndexedDB combines the strengths of the LocalStorage and WebSQL  stores arbitrary JavaScript objects indexed with a key, like local storage  can create multiple databases, with multiple stores per database  asynchronous design and search indexes provide performance benefits.

IndexedDB 14  When you make a request, you get a request object, which provides onerror and onsuccess events  properties such as result, error and readyState

Creating/Opening a Database 15 var db; var dbName = 'myDB'; var databaseVersion = 1 var openRequest = window.indexedDB.open(dbName [,databaseVersion]); openRequest.onerror = function (e) { console.log(e.target.errorCode); }; openRequest.onsuccess = function (event) { // Database is open and initialized db = openRequest.result; … }; NOTE: The database is created if a database with the specified name does not exist. Only a single version of a database can exist at a time. When a database is first created, its initial version is zero

Delete A Database 16 function deleteDatabase() { var deleteDbRequest = window.indexedDB.deleteDatabase(dbName); deleteDbRequest.onsuccess = function (event) { // database deleted successfully }; deleteDbRequest.onerror = function (e) { console.log("Database error: " + e.target.errorCode); }; }

Working with Object Stores 17  a collection of data records  to create/modify an object store in an existing database  need to version the existing database, by opening the database for versioning  In addition to the database name, add the version number as a second parameter  Use a higher version than the current existing database version  This invokes the onupgradeneeded event handler.

Creating/Updating an object store 18 function createObjectStore() { var openRequest = window.indexedDB.open(dbName, 2); openRequest.onerror = function(e) { console.log("Database error: " + e.target.errorCode); }; openRequest.onsuccess = function(event) { db = openRequest.result; }; openRequest.onupgradeneeded = function (evt) { var employeeStore = evt.currentTarget.result.createObjectStore ("employees", {keyPath: "id"}); }; }

Indexes 19  Can retrieve records in an object store using its key or indexed fields  can have one or more indexes  To create an index, you must version the  Indexes can either be unique or non-unique function createIndex() { var openRequest = window.indexedDB.open(dbName, 2); openRequest.onsuccess = function(event) { db = openRequest.result; }; openRequest.onupgradeneeded = function (evt) { var employeeStore = evt.currentTarget.result.objectStore("employees"); employeeStore.createIndex("stateIndex", "state", { unique: false }); employeeStore.createIndex(" Index", " ", { unique: true }); employeeStore.createIndex("zipCodeIndex", "zip_code", { unique: false }) }; }

Transactions 20  Used to perform reading and writing operations on an object store  Three modes:

Retrieve a specific record using key 21 function fetchEmployee() { try { var result = document.getElementById("result"); result.innerHTML = ""; if (db != null) { var store = window.db.transaction("employees“,”readwrite”).objectStore("employees"); store.get("E3").onsuccess = function(event) { var employee = event.target.result; if (employee == null) { result.value = "employee not found"; } else { var jsonStr = JSON.stringify(employee); result.innerHTML = jsonStr; } }; } catch(e){ console.log(e); }

Retrieve a specific record using an index 22 function fetchEmployeeBy () { try { var result = document.getElementById("result"); result.innerHTML = ""; if (db != null) { var range = var store = window.db.transaction("employees").objectStore("employees"); var index = store.index(" Index"); index.get(range).onsuccess = function(evt) { var employee = evt.target.result; var jsonStr = JSON.stringify(employee); result.innerHTML = jsonStr; }; } catch(e){

Retrieve all records 23 function fetchEmployeeBy () { try { var result = document.getElementById("result"); result.innerHTML = ""; var store = window.db.transaction("employees“,”readwrite”).objectStore("employees"); var request = store.openCursor(); request.onsuccess = function(evt) { var cursor = evt.target.result; if (cursor) { var employee = cursor.value; var jsonStr = JSON.stringify(employee); result.innerHTML = result.innerHTML + “ " + jsonStr; cursor.continue(); } }; } catch(e){