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 6093113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:31:24+00:00 2026-05-23T12:31:24+00:00

I have a jQuery Mobile web app which targets iOS and Android devices. A

  • 0

I have a jQuery Mobile web app which targets iOS and Android devices. A component of the application is a background task, which periodically checks for a.) changes to local data and b.) connectivity to the server. If both are true, the task pushes the changes.

I’m using a simple setTimeout()-based function to execute this task. Each failure or success condition calls setTimeout() on the background task, ensuring that it runs on 30 second intervals. I update a status div with the timestamp of the last task runtime for debugging purposes.

In any desktop browser, this works just fine; however, on iOS or Android, after some period of time, the task stops executing. I’m wondering if this is related to the power conservation settings of the devices–when iOS enters stand-by, does it terminate JavaScript execution? That is what appears to happen.

If so, what is the best way to resume? Is there an on-wake event which I can hook into? If not, what other options are there which don’t involve hooking into events dependent on user interaction (I don’t want to bind the entire page to a click event just to restart the background task).

  • 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-05-23T12:31:24+00:00Added an answer on May 23, 2026 at 12:31 pm

    Looks like Javascript execution is paused on MobileSafari when the browser page isn’t focused. It also seems if setInterval() events are late, they are simply fired as soon as the browser is focused. This means we should be able to keep a setInterval() running, and assume the browser lost/regained focus if the setInterval function took much longer than usual.

    This code alerts after switching back from a browser tab, after switching back from another app, and after resuming from sleep. If you set your threshold a bit longer than your setTimeout(), you can assume your timeout wouldn’t finish if this fires.

    If you wanted to stay on the safe side: you could save your timeout ID (returned by setTimeout) and set this to a shorter threshold than your timeout, then run clearTimeout() and setTimeout() again if this fires.

    <script type="text/javascript">
    var lastCheck = 0;
    
    function sleepCheck() {
            var now = new Date().getTime();
            var diff = now - lastCheck;
            if (diff > 3000) {
                    alert('took ' + diff + 'ms');
            }
            lastCheck = now;
    }
    
    window.onload = function() {
            lastCheck = new Date().getTime();
            setInterval(sleepCheck, 1000);
    }
    </script>
    

    Edit: It appears this can sometimes trigger more than once in a row on resume, so you’d need to handle that somehow. (After letting my android browser sleep all night, it woke up to two alert()s. I bet Javascript got resumed at some arbitrary time before fully sleeping.)

    I tested on Android 2.2 and the latest iOS – they both alert as soon as you resume from sleep.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application built with jQuery Mobile and PHP (CodeIgniter framework). Now
We have an existing web app built with jQuery Mobile. Our goal is to
Say I have a mobile web app written using JQuery Mobile, this app retrieves
I'm building a mobile web app with jQuery Mobile and I have a problem.
I am using jQuery Mobile in my web application. There is a datepicker which
We have a simple mobile web application using jQuery. The application is working good
I have a web app of which I would like to create a mobile
I am developing a mobile web app. Currently I have this snippet of jQuery
I have a mobile web application built using the following versions :- JQuery Mobile
I've been toying with writing a web app using jquery mobile which makes use

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.