Alert from an app when it's closed

Hello,

I hope someone can help me out.

I’ve been working on an app where users add in the settings menu (in 24-hour format) the time when they wish to be alerted for some thing or another – they have up to 10 slots.  I want them to get the alert and alarm when they are NOT in the app; but I can’t get it to work properly.  Most times it does not work, unless intermittently when they manually resync their device, and even then they get alerted at the wrong time.

My code is as follows:-

currentTime = current time

nextTime = alarm time set by user

nextEvent = name of next event

promptMessageNotification = the alarm message

AppView.mc:

// Send notification message to background event to trigger alarms
if (nextTime != currentTime) {
			promptMessageNotification = "";
		} else {
			promptMessageNotification = "ALARM!!\n”+nextEvent;
		}
		Storage.setValue("PromptMessageNotification", promptMessageNotification);
// background event to notify user when event is due, outside of the app
    function setBackgroundEvent() {
    System.println("Temporal Event set");
    if (nextTime != currentTime) {
    	} else {   	
    	Background.registerForTemporalEvent(nextTimeAlarm);
    	}
    }

AppApp.mc:

(:background)
class AppApp extends Application.AppBase {

var notificationView;
    // onStop() is called when your application is exiting
    function onStop(state) {
  	if (notificationView) {
  		notificationView.setBackgroundEvent();
  		}		
    }
    // Return the initial view of your application here
    function getInitialView() {
   		notificationView = new AppView();           
        return [ notificationView, new AppDelegate()];
    }
     function getServiceDelegate() {
		   return [new BackgroundService()]; 
	 }
}

BackgroundService.mc:

(:background)
class BackgroundService extends System.ServiceDelegate {	
	var promptMessageNotification1 = Storage.getValue("PromptMessageNotification") == null ? "" : Storage.getValue("PromptMessageNotification");
	 
	function initialize() {
		System.ServiceDelegate.initialize();
		System.println(promptMessageNotification1);
	}
	
	function onTemporalEvent() {
		if (promptMessageNotification1.equals("")) {
			Background.exit(null);
		} else {
        	Background.requestApplicationWake(promptMessageNotification1);
        	Background.exit(null);
        }
    }
    	
}

I would really appreciate some help with this.  Thanks in advance.

  • Hi , I know you're a Garmin expert around here, so I was wondering if you could give me some advice on this background event problem I'm having, if possible?  Thanks

  • I've never really used Background.requestApplicationWake(), but I'd start with adding a bunch of println calls and do a sideload while precreating the apps log file.

  • Thanks for reaching out; much appreciated and sorry I had to tag you in, but I'm desperate!

    Would you be able to point me in the direction of where I need to add the printin calls - would it be in the temporal event function itself?  I've been doing a sideload with a log to my device; but what would I be looking for in the log to see where the error would be?  Sorry, but I'm still relatively new at Garmin coding Open mouth

  • Background.requestApplicationwake really doesn't work properly on any device I've looked at, on some devices it hangs, on some devices there is no vibration accompanied with the message, etc... I've filed numerous bug reports on the api, but because this needs to be fixed on the device side every device team needs to apply the fix to make it work. To be honest I've given up hope on seeing this ever fixed. 

  • Thank you very much for this confirmation - it's as I feared!

    The really bad thing was that I created and published an app with it because it initially worked on my vivoactive 4S (otherwise I would not have released it in the first place), but users are complaining it's not working and now I can't get it to work either, and I don't know how to fix it; I've tried everything!

    I think it's really bad when a manufacturer puts out a function and won't fix the issue, because then we would then try to make use of it and have egg on our faces when we discover it doesn't work at all!

    I will still hold out hope that it can work someday, and also in case if anyone has any kind of solution I can use.

  • I'm put in println calls for things like when you register the temporal evnt, when onTemporalEvent runs - to understand the actual flow of things.  But as Peter said, I recall there were issues with requestApplicationWake()

    That's one of the reasons I've never really used it.

  • Thank you for getting back to me.  I had previously looked on the forums for requestApplicationWake and could not recall if anyone else were experiencing problems, so it's good in a way to finally get official closure that it's faulty; at least I know it's nothing I have done wrong!

    I will still take your advice and add further logs just to check if the flow is OK.

  • If you use the search with the magnifying glass and search for requestApplicationWake you'll find a number of threads in discussion.

    Here's one started by Peter for example:
    https://forums.garmin.com/developer/connect-iq/f/discussion/5726/fr735xt---requestapplicationwake-does-not-buzz-nor-beep

  • Thank you.  At this stage I would have been happy if the message popped up in the first place without the vibration, although I had set it with vibration to further alert the user.  If the message was at least showing up it would be better than nothing.