Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap local storage

Tags:

cordova

I'm developing a multi-language PhoneGap app and would like to store the user's language preference. On first launch of the app a splash screen would come up with 4 flags, user picks, and then is directed to a landing page in that language. From then on the app load skips the splash screen and goes straight to the landing page in the preferred language. Easy to do? Suggestions? I'm familiar with cookies/local storage but if anyone has done this before I would appreciate specific directions. Thanks.

like image 905
user625808 Avatar asked Apr 22 '11 09:04

user625808


People also ask

Does LocalStorage work in Cordova?

LocalStorage. Local storage provides simple, synchronous key/value pair storage, and is supported by the underlying WebView implementations on all Cordova platforms.

Is Cordova discontinued?

Apache Cordova Is Retired: Alternatives for Cross Platform Mobile Development in 2022. Future trends of cross-platform mobile development are already starting to emerge, and it appears that Apache Cordova won't be included in the list of frameworks that power hybrid web apps for mobile devices.

Who developed PhoneGap Apache?

PhoneGap is one such platform which we specialize in. What is PhoneGap? PhoneGap is an emerging open source mobile application development platform best suited for cross-platform compliant mobile applications. Developed by Apache Software Foundation, PhoneGap is also known as Apache Cordova.


2 Answers

What you describe should be very easy to do with localStorage. I researched it before using it on Android, and found this webpage to have very helpful code examples and explanations. Very short and sweet.

like image 172
Libby Avatar answered Nov 07 '22 09:11

Libby


To save to local storage use:

  function saveLanuageID(languageID)
    window.localStorage.setItem('lang', languageID);

Read from local storage

function readLanguageID(){
if (typeof window.localStorage.getItem('lang')!== 'undefined' &&  window.localStorage.getItem('lang')!=null) {
    return window.localStorage.getItem('lang');
 }
else return false
}

You would have to test for saved language using the code above

if(!readLanguageID())
//redirect to splash
like image 43
ShiftyThomas Avatar answered Nov 07 '22 09:11

ShiftyThomas