title: ionic + cordova plugin and background mode
body: <p>I'm making an app with ionic for car drivers. The app takes coordinates every one minute and write them on remote server, this helps me to tracking route and show cars on Google map. </p>
  
  <p>I use Cordova plugin and it works fine except when screen turns off or the app goes into the background. I installed katzer cordova-plugin-background-mode, when the app go into background I see the message : app is now in background, the plugin informs me but nothing else, the app stopped! .</p>
  
  <p>No data sent to remote server, when I resume the app all is back to normal, I use Android platform. How can i solve? </p>
  
  <p>app.js code</p>
  
  <p><pre><code></p>
  
  <pre><code>angular.module('starter', ['ionic', 'ngCordova','LocalStorageModule', 'starter.controllers', 'starter.services'])
  
  .run(function ($ionicPlatform) {
      $ionicPlatform.ready(function () {
          // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
          // for form inputs)
          if (window.cordova &amp;&amp; window.cordova.plugins &amp;&amp; window.cordova.plugins.Keyboard) {
              cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
          }
          if (window.StatusBar) {
              // org.apache.cordova.statusbar required
              StatusBar.styleLightContent();
          }
  
          cordova.plugins.backgroundMode.enable();
  
      });
  })
  .....
  </code></pre>
  
  <p></pre></code></p>
  
  <p>controllers.js
  <pre><code></p>
  
  <pre><code>angular.module('starter.controllers', [])
  
  .controller('GeoCtrl', function($scope, $cordovaGeolocation, $cordovaNetwork, $http, $interval) {
  
  
  var reloadCoordinates = function() {
  
    var watchOptions = {
      timeout : 10000,
      enableHighAccuracy: false // may cause errors if true
    };
  
    var watch = $cordovaGeolocation.watchPosition(watchOptions);
  
    watch.then(
      null,
      function(err) {
        // error
  
      },
      function(position) {
        //Latitudine e Longitudine
        var lat  = position.coords.latitude
        var lon = position.coords.longitude
  
        $scope.latitude  = lat 
        $scope.longitude = lon
  
  
        $http.post('http://192.168.1.2/get-data.php', { "lat": lat, "lon" : lon }).then(function(resp) {
                console.log('Success Lat:'+resp.data.lat+' Lon:'+resp.data.lon);
                watch.clearWatch();
  
            }, function(err) {
                console.error('ERR', err);
                // err.status will contain the status code
        })
  
    });
  
  
   };//end reloadCoordinates
  
  
   $interval(reloadCoordinates, 60000);
  
   reloadCoordinates();
  
  })
  </code></pre>
  
  <p></pre></code></p>