I need to force the crash of an Android App, from inside a Cordova plug-in class.
The problem is that the plug-in class runs in a separated Thread, so even if I force a RuntimeException()
, it crashes just the separated thread.
I need to force the crash of an Android App, from inside a Cordova plug-in class.
The problem is that the plug-in class runs in a separated Thread, so even if I force a RuntimeException()
, it crashes just the separated thread.
What your plugin code should do is to define handler on your for unhandled exception as defined on Rahits answer. Idea is to attach to event like this (code borrowed from the answer linked)
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
Log.e("Error"+Thread.currentThread().getStackTrace()[2],paramThrowable.getLocalizedMessage());
}
});
and then when the callback is called, throw the real exception which causes the desired effect.
If you want to crash the app from cordova plugin/or pressing menu button in android app you have to edit few classes in cordova project as mentioned in how to make my phonegap android app crash?.
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)
With this change I am able to crash the application from javascript call.