I am developing a crash reporter plugin for phonegap android apps. For the testing purpose, I have to make my application crash & \"Unfortunately, application has stopped\"
Crash by pressing menu button:
You cannot make the app crash from a plugin or javascript call as the exceptions are handled internally. If you want to make the app crash in android you can edit CordovaActivity.java in Android platform. Change onCreateOptionsMenu as shown:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
this.postMessage("onCreateOptionsMenu", menu);
throw new RuntimeException();
}
Press the menu button and app will crash & "Unfortunately, application has stopped" window will be displayed.
Crash by calling some native function from Javascript:
Write an Android native plugin for Phonegap. Refer http://docs.phonegap.com/en/3.0.0/guide_platforms_android_plugin.md.html#Android%20Plugins for plugin creation. Throw exception inside execute method. This will be handled in the parent layer(Thats why you can see logs about crash in the console), So please do following changes to make the app crash.(Both the classes belong to org.apache.cordova package)
catch (Exception e){}
block in execHelper method of pluginManager classs.Remove catch (Throwable e) {}
block in exec method of ExposedJsApi class.
With this change I am able to crash the application from javascript call.