Cody Blue
Posts: 0
Joined: Sun Aug 25, 2013 2:11 am

resume and offline event handling order

I handle "resume" (document.addEventListener("resume", onResume , false);) and "offline" events in an Appery project.

It seems the cordova handles resume first and then offline.

However, depending on whether on not the device is connected I need to make decisions within onResume function above. My question is if there is a way for me to detect that device is offline or online while handling the "resume" event?

Suggestions would be appreciated.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

resume and offline event handling order

Hi -

[quote:]However, depending on whether on not the device is connected I need to make decisions within onResume function above. My question is if there is a way for me to detect that device is offline or online while handling the "resume" event? [/quote]
Yes - you can for a example make a dummy request or service call. And handle the events - success or error. If its 'offline' then don't execute the resume event.
pre
code
var onSuccess = function(){
alert("online");
};
var onError = function(){
alert("online");
};

serviceName.execute({success: onSuccess, error: onError});
/code
/pre

Cody Blue
Posts: 0
Joined: Sun Aug 25, 2013 2:11 am

resume and offline event handling order

Thanks for the feedback here. This could be viable, but I am bit concerned that if the error is due to other factors (timeout, etc.) wouldn't the "offline" assumption be invalid?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

resume and offline event handling order

Hi Cody,

You right, this approach could get a mistake. But online/offline events based on the same mechanism. There is no other way to define is there a connection to external source.

Regards.

Return to “Issues”