title: Cordova app closes unexpectedly
body: <p>I developed a hybrid app using cordova. I uploaded it to google play and app store. Users reported that they are getting a message "Unfortunately, xxx has closed" (xxx represents the app name). While testing I am not able to reproduce the issue. The strange part is users get this message when they are not using my app. I had the following plugins installed in my app</p>
  
  <pre><code>cordova-plugin-camera 2.2.1-dev "Camera"
  cordova-plugin-compat 1.0.0 "Compat"
  cordova-plugin-device 1.1.1 "Device"
  cordova-plugin-file 4.1.0 "File"
  cordova-plugin-file-transfer 1.5.0 "File Transfer"
  cordova-plugin-geolocation 2.1.0 "Geolocation"
  cordova-plugin-inappbrowser 1.4.0 "InAppBrowser"
  cordova-plugin-network-information 1.2.0 "Network Information"
  cordova-plugin-splashscreen 3.2.2 "Splashscreen"
  cordova-plugin-statusbar 2.1.4-dev "StatusBar"
  cordova-plugin-whitelist 1.2.2 "Whitelist"
  cordova-plugin-x-toast 2.3.2 "Toast"
  cordova-sqlite-storage 0.7.14 "Cordova sqlite storage plugin"
  cordova.plugins.diagnostic 3.0.2 "Diagnostic"
  ionic-plugin-keyboard 2.2.0 "Keyboard"
  phonegap-plugin-barcodescanner 5.0.0 "BarcodeScanner"
  phonegap-plugin-push 1.6.4 "PushPlugin"
  </code></pre>
  
  <p>Ios users are not getting this crash message. Only android users reported this issue. </p>
  
  <p>Here is my Androidmanifest.xml file</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.xxx.yy" xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true"&gt;
          &lt;activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize"&gt;
              &lt;intent-filter android:label="@string/launcher_name"&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;receiver android:name="cordova.plugins.Diagnostic$LocationProviderChangedReceiver"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.location.PROVIDERS_CHANGED" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;activity android:clearTaskOnLaunch="true" android:configChanges="orientation|keyboardHidden|screenSize" android:exported="false" android:name="com.google.zxing.client.android.CaptureActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.zxing.client.android.SCAN" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:label="Share" android:name="com.google.zxing.client.android.encode.EncodeActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.phonegap.plugins.barcodescanner.ENCODE" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:label="Share" android:name="com.google.zxing.client.android.HelpActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.VIEW" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:exported="true" android:name="com.adobe.phonegap.push.PushHandlerActivity" /&gt;
          &lt;receiver android:name="com.adobe.phonegap.push.BackgroundActionButtonHandler" /&gt;
          &lt;receiver android:exported="true" android:name="com.google.android.gms.gcm.GcmReceiver" android:permission="com.google.android.c2dm.permission.SEND"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
                  &lt;category android:name="${applicationId}" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;service android:exported="false" android:name="com.adobe.phonegap.push.GCMIntentService"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt;
          &lt;service android:exported="false" android:name="com.adobe.phonegap.push.PushInstanceIDListenerService"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.android.gms.iid.InstanceID" /&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt;
          &lt;service android:exported="false" android:name="com.adobe.phonegap.push.RegistrationIntentService" /&gt;
      &lt;/application&gt;
      &lt;uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
      &lt;uses-permission android:name="android.permission.FLASHLIGHT" /&gt;
      &lt;uses-feature android:name="android.hardware.camera" android:required="false" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
      &lt;uses-permission android:name="android.permission.VIBRATE" /&gt;
      &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
      &lt;permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" /&gt;
      &lt;uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" /&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I had two functions in my code, which invoke automatically. Both are used to sync the data to server. </p>
  
  <pre><code>$interval(function() {
          var isOnline = $cordovaNetwork.isOnline();
          if (isOnline) {
              $scope.syncData();
          }
      }, 900000)
  </code></pre>
  
  <p>and </p>
  
  <pre><code>$rootScope.$on('$cordovaNetwork:online', function(event, networkState) {
          if ($scope.isLoggedIn) {
              var onlineState = networkState;
              console.log('Online State', onlineState);
              $scope.syncData();
          }
  
      });
  </code></pre>
  
  <p>Will this functions call in background ? Will this functions persist after app close ?
  I couldn't find anything unusual during debug. 
  Can anyone help me ?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I found two scenarios this occurred: </p>
  
  <ol>
  <li>I was changing the network state to flight mode due to network
  issue. Suddenly I got the message that Unfortunately xxx has stopped</li>
  <li>My GPS was disabled. I was trying to open google maps. I got a
  message from google map to enable GPS. At the time I enabled GPS, I
  got message that Unfortunately xxx has stopped</li>
  </ol>