Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-8383

pause event don't fire when 'KeepRunning' is false

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • Master, 3.5.0, 4.0.0, 4.1.3
    • None
    • cordova-android
    • None
    • Mac osx 10.9

    Description

      Under Android, when a project use 'KeepRunning=false' in the config.xml file, the 'pause' event in javascript don't fire when application go to background. Next, 'pause' event fire when 'resume' is call and when the application resume.
      The problem is in 'CordovaWebView.java' in the 'handlePause' method :

      public void handlePause(boolean keepRunning) {
      LOG.d(TAG, "Handle the pause");
      // Send pause event to JavaScript
      this.loadUrl("javascript:try

      {cordova.fireDocumentEvent('pause');}

      catch(e)

      {console.log('exception firing pause event from native');}

      ;");

      // Forward to plugins
      if (this.pluginManager != null)

      { this.pluginManager.onPause(keepRunning); }

      // If app doesn't want to run in background
      if (!keepRunning)

      { // Pause JavaScript timers (including setInterval) this.pauseTimers(); }

      paused = true;

      }

      As you can see, 'pauseTimers()' is call immediatly when we choose 'KeepRunning' false.
      According to the Android documentation, 'pauseTimer()' stop all javascript activity....then the 'pause' javascript callback is not execute (it's execute after, when the 'resumeTimers()' is call and the application resume.

      I suggest to delay the 'pauseTimers()' for 1 or 2 sec. Then the javascript 'pause' can execute before the application is really stop :

      //OLD
      //this.pauseTimers();

      //NEW
      final Handler handler = new Handler();
      handler.postDelayed(new Runnable() {
      @Override
      public void run()

      { LOG.d(TAG, "Handle the pauseTimers"); pauseTimers(); }

      }, 1000);
      }

      Thanks.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              hugefactory hugefactory
              Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 1h
                  1h
                  Remaining:
                  Remaining Estimate - 1h
                  1h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified