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" window has to be invoked. When I make an unhandled exception in the javascript, the app is not crashing. Instead its showing the same screen. I made the app screen stop respond to user input by executing some infinite loop in javascript & waited around 1 hour, still the app was not crashing. Is the phonegap library by default handling the exceptions ? how I can make my app crash by making exception in javascript level ?
I tried the below code,added a java method to generate crash in the 'CordovaActivity' class.
public static void generateCrash() { int a = 0; int b = 10; int c = b/a ; }
The app is crashing when I call this method from java (from the 'onCreate' in the activity class) . But when I invoke the same method from the javascript using plugin, the app is not crashing. I want my app to crash by calling/invoking some function from the javascript.
Apps on Android can crash because of low storage space, too many apps running simultaneously, a weak internet connection, or not having the proper app updates installed.
An app that is written using native-code languages crashes if there's an unhandled signal, such as SIGSEGV, during its execution. When an app crashes, Android terminates the app's process and displays a dialog to let the user know that the app has stopped, as shown in figure 1.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With