Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make my phonegap android app crash?

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.

like image 311
Sinu Varghese Avatar asked Feb 05 '15 09:02

Sinu Varghese


People also ask

What causes app crashes on Android?

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.

What is Native crash Android?

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.


1 Answers

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)

  • Remove 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.

like image 66
kumar Avatar answered Oct 09 '22 08:10

kumar