Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Local storage in phone gap

Tags:

I wanted to create an mobile app for my web project. I found phonegap. It says Easily create apps using HTML, CSS, and JavaScript. I have not created a mobile app using phone gap before. There are three storage options memory-store.js (MemoryStore), ls-store.js (LocalStorageStore) and websql-store.js (WebSqlStore). I just want to save a token to recognise the user. Which storage is best suited. Is there a better way to build an mobile app.

I appreciate any help.

like image 604
Leah Collins Avatar asked Apr 12 '13 10:04

Leah Collins


People also ask

What are the storage options does PhoneGap can access?

SQLite is essentially the only way to persistently store unlimited data for PhoneGap applications, however other options I will cover in the rest of this post can also be made persistent and have unlimited data storage by using SQLite as a backend.

Does local storage works in mobile?

Nowadays, through the use of LocalStorage, we can store data on clients like browsers and mobile apps without communicating with a back-end application. In this article, we will discuss how developers can store data on the client with cookies and how LocalStorage improved that experience.

How does a PhoneGap application interact with the native components?

PhoneGap: It is a framework for mobile application development, built upon the open source Apache Cordova project. It permits you to write an app once with CSS, JavaScript, HTML and then deploys it to a broad range of mobile devices without losing the features of a native app.


1 Answers

Using Local Storage will probably be easiest for your needs.

Fundamentally speaking PhoneGap apps are native apps (so they can be distributed through app stores) that simply run a web page or pages. The PhoneGap API then provides JavaScript hooks into the device functions like camera etc. Theres more to it but for now thats the background.

So since the app is essentially a web page (HTML5, CSS, JS) you can make use of LocalStorage (part of HTML5).

Example local storage usage:

Setting values:

localStorage.myname = "Greg"; 

Getting values:

localStorage.myname; // returns "Greg" 

More information here for local storage: http://diveintohtml5.info/storage.html

For Windows Phone 7 : http://docs.phonegap.com/en/3.4.0/cordova_storage_storage.md.html#Storage

The syntax is as below

localStorage.setItem("name", "Alen");  localStorage.getItem("name"); //will return Alen 
like image 89
Greg Avatar answered Sep 21 '22 20:09

Greg