title: Phonegap 3.2.0 "Unfortunately, AppName has stopped." dialog when closing app
body: <p>When I close my app, I get a dialog box saying "Unfortunately, MyApp has stopped." and an OK button.  By closing, I mean pressing the back button from the first screen.  The app does close fine, but then this dialog appears a few seconds later.</p>
  
  <p>I'm using PhoneGap 3.2.0.  It didn't happen prior to updating to 3.x.x. I'm not sure exactly which version after this is the culprit.</p>
  
  <p>The LogCat in Eclipse puts out this when it happens:</p>
  
  <pre><code>01-13 15:20:42.764: D/CordovaActivity(32367): onMessage(exit,null)
  01-13 15:20:42.829: D/CordovaActivity(32367): Paused the application!
  01-13 15:20:42.839: W/PluginManager(32367): THREAD WARNING: exec() call to App.exitApp blocked the main thread for 74ms. Plugin should use CordovaInterface.getThreadPool().
  01-13 15:20:43.219: W/IInputConnectionWrapper(32367): showStatusIcon on inactive InputConnection
  01-13 15:20:43.254: D/CordovaActivity(32367): CordovaActivity.onDestroy()
  01-13 15:20:43.259: D/CordovaWebView(32367): &gt;&gt;&gt; loadUrlNow()
  01-13 15:20:43.284: D/AndroidRuntime(32367): Shutting down VM
  01-13 15:20:43.284: W/dalvikvm(32367): threadid=1: thread exiting with uncaught exception (group=0x417752a0)
  01-13 09:56:40.404: E/AndroidRuntime(13858): java.lang.RuntimeException: Unable to destroy activity {MyAppName}: java.lang.IllegalArgumentException: Receiver not registered: null
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3314)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3332)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.app.ActivityThread.access$1200(ActivityThread.java:140) 
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.os.Handler.dispatchMessage(Handler.java:99) 
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.os.Looper.loop(Looper.java:137) 
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.app.ActivityThread.main(ActivityThread.java:4898)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at java.lang.reflect.Method.invokeNative(Native Method)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at java.lang.reflect.Method.invoke(Method.java:511)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at dalvik.system.NativeStart.main(Native Method)
  01-13 09:56:40.404: E/AndroidRuntime(13858): Caused by: java.lang.IllegalArgumentException: Receiver not registered: null
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:654)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1277)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:385)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at org.apache.cordova.device.Device.onDestroy(Device.java:98)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at org.apache.cordova.PluginManager.onDestroy(PluginManager.java:332)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at org.apache.cordova.CordovaWebView.handleDestroy(CordovaWebView.java:833)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at org.apache.cordova.CordovaActivity.onDestroy(CordovaActivity.java:774)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.app.Activity.performDestroy(Activity.java:5370)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1113)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3301)
  01-13 09:56:40.404: E/AndroidRuntime(13858):    ... 11 more
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Until now, I've always been using the line
  navigator.app.exitApp();
  to close the app if I detect that I'm on the index.html page when the back button is pressed.</p>
  
  <p>I tried instead to remove the backbutton listener and restore the default behaviour when the back button was pressed.  It still results in the same problem.</p>
  
  <p>Here's some shortened code snippets:</p>
  
  <pre><code>$(document).ready(function ()
  {
      document.addEventListener("deviceready", onDeviceReady, false);
  }
  
  function onDeviceReady()
  {
      document.addEventListener("backbutton", backButton, false);
  });
  
  function backButton()
  {
      var currentLocation = window.location.href.substr(window.location.href.lastIndexOf("/")+1);
      switch (currentLocation) {
      case 'index.html':
      navigator.app.exitApp();
      break;
  }
  </code></pre>
  
  <p><strong>Update 2014/01/13 16:00:</strong>
  Not sure if it is any help, but I've noticed that it doesn't give any errors if I comment out the script src="cordova.js" from index.html.</p>