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

  • SEARCH
  • Home
  • 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 8731147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:09:54+00:00 2026-06-13T09:09:54+00:00

I am using the PhoneGap LocalNotification plugin, which allows me to set local notifications

  • 0

I am using the PhoneGap LocalNotification plugin, which allows me to set local notifications at certain times.

The basic structure of the LocalNotification plugin is like this:

var notification = {
    init: function () {

    },
    clear_all: function () {
        notification.clear();
        plugins.localNotification.add({
            badge: 0,
        });

    },
    alert_ten: function () {
        var d = new Date();
        d = d.getTime() + 10 * 1000; //60 seconds from now
        d = new Date(d);
        plugins.localNotification.add({
            date: d,
            repeat: 'daily',
            message: varone + ' - ' + vartwo + '!',
            hasAction: true,
            badge: 1,
            id: '1',
            sound: 'horn.caf',
            background: 'app.background',
            foreground: 'app.running'
        });
    },
}

If you look at the message part of the notification, it consists of the following varone + ' - ' + vartwo + '!'. On page load, varone and vartwo are populated from a localStorage item. I then call notification.alert_ten() onLoad.

This all works fine, but there is one exception:

The localStorage items are set when the user interacts with a certain div, i.e., clicks it. Then, when the app is loaded, it checks to see these values, and alerts the message after 10 seconds, saying that this and that, which get their values from the LS.

If the user changes their mind, and interacts with a different div, which changes the LS items, the LocalNotification still runs with the original set of LS items.

This is to be expected, as JS will cache the variable within the function. A solution that I thought would work would be to define the variables globally, above var notification = {, and then when the user interacts with the div, update the vars to represent the new variables.

Global variables:

var varone = localStorage.getItem("favorite");
var vartwo = localStorage.getItem("favorite-status").substr(2).toLowerCase();
...

Updated variables:

...
var varone = text;
var vartwo = favstatus;
...

The function, notification.alert_ten() still runs with the original values defined within the global variable, instead of the updated ones.

  • 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-13T09:09:55+00:00Added an answer on June 13, 2026 at 9:09 am

    You could write getter/setter functions. This is just a proof of concept, you can add whichever methods to this that you like. Just make sure to add this. before any property that you want to share between functions inside the object, or that you want accessible from outside the object.

    var notification = {
      setX : function (newX) {
        this.x = newX;
      },
      getX : function () {
        return this.x;
      },
      outputX : function () {
        document.write('x is ' + this.x + '<br>');
      }
    }
    

    Initialize and use:

    notification.setX(42);
    console.log(notification.getX());
    

    or

    notification[x] = 42;
    console.log(notification[x]);
    

    or even

    notification.x = 42;
    console.log(notification.x);
    

    DEMO

    So your code could be something like (weeding out all but the interesting parts)

    var notification = {
        getMessage: function() {
            return this.message;
        },
        setMessage: function() {
            this.message = localStorage.getItem("favorite") + ' - ' + 
                           localStorage.getItem("favorite-status").substr(2).toLowerCase() + '!';
        },
        alert_ten: function () {
            plugins.localNotification.add({
                message: this.getMessage()
            });
        }
    }
    
    // After some event I guess
    notification.setMessage();
    // After some other event?
    notification.alert_ten();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have implemented a local notification in my android app using phonegap localnotification plugin.
I'm using the phonegap localNotifications plugin which specifies that I can set a notification
I am using Phonegap 1.3.0, and want to develop an app which uses local
In my PhoneGap 1.3 offline app I'm using modified iOS local notification plugin found
I am currently trying to use the PhoneGap LocalNotification Plugin , using Android 4.1
I'm using PhoneGap + jQuery Mobile for a new mobile app. This plugin is
I'm using Phonegap (Cordova) v1.9, and this app is solely for iPhone4+ use. I've
I am using PhoneGap, jQuery mobile in Xcode. I have a local xml (data.xml)
I develop an app using PhoneGap. I got a service which is in background
I am developing a mobile application using phonegap and jquery mobile. I have this

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.