Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7999295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:27:56+00:00 2026-06-04T15:27:56+00:00

I have an app for Android (and hopefully later iPhone) that is based on

  • 0

I have an app for Android (and hopefully later iPhone) that is based on Javacript and is made into an app using Phonegap/Applaud.

Unfortunately, setting and getting cookies is not working on Android, and this might be particular to the Android environment. I was advised that using “local storage” might be more reliable.

However, I knew nothing about local storage until this morning, and so I’m struggling to get aquainted. From what I gather, it’s basically just another place to save data with a different syntax. For my situation, I don’t think it gives me any advantages over cookies other than the fact that Android is forcing me to use it. As a result, I’m hoping I can still leverage my existing code for setting and getting cookies, and not have to take on a whole new approach.

Surely I can just do a test in my Javascript to see if there is local storage, and if so, store and retrieve my cookie data there, and if not, then just use cookies as normal?

Note 1: I searched Stack Overflow for similar questions, and there was this one which at first seems exactly what I’m talking about, but it’s too terse so I can’t parse it to know what I should do with it. Also, I think it assumes the presence of libraries and code that I don’t think I have. I also looked at this question but I think it’s doing the reverse of what I’m after.

Note 2: This is my current code for getting and setting cookies (procured from somewhere on the web. Up until the Android problem, was rock solid reliable):

function getCookie(c_name)
{
    var c_start = document.cookie.indexOf(c_name + "=");

    if (document.cookie.length > 0)
    {
        if (c_start !== -1)
        {
            return getCookieSubstring(c_start, c_name);
        }
    }
    return "";
}

function setCookie(c_name, value, expiredays)
{
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + expiredays);
        document.cookie = c_name + "=" + escape(value) +
        ((expiredays === null) ? "" : ";expires=" + exdate.toUTCString());
        alert("this is document.cookie: " + document.cookie);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:27:58+00:00Added an answer on June 4, 2026 at 3:27 pm

    Have a look at http://diveintohtml5.info/storage.html. The history might not be very interesting at all, but it at least provides an excellent link list to other tutorials in the further-reading section.

    So, now to your code. The first thing to mention is that localStorage has no expire – it’s persistent (until the user manually cleans everything). If you’d like to use some shorter storage, you might also use sessionStorage, which has the same interface but last only until the browser is closed.

    Rephrasing your code is simple:

    function getCookie(c_name) {
        return localStorage.getItem(c_name);
    }
    
    function setCookie(c_name, value, expiredays) {
        return localStorage.setItem(c_name, value);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app built for Android (and hopefully soon iPhone) using Phonegap 's
I have PhoneGap app in Android using jQuery. Sometimes I need to upload some
I have an Android app that I had working a few months ago which
I have an Android app that begins by displaying a dialog. When I set
I have an app in android using camera with opencv which runs for about
I have android app that talks to server and syncs some data int SQLite
I have an app in the android market that is reporting incomparability and so
I have PhoneGap app in Android. Now I am ready to publish it, but
I have an app in android that in a different thread from the UI(which
I have an app on Android Market that should run on everything >= Android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.