I use the following code to automatically relaunch my app in case of any unhandled exception.
private Thread.UncaughtExceptionHandler onCrashRestart = new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread thread, Throwable ex) {
LOGGER.error("Unhandled Runtime exception occured ", ex);
LOGGER.info("Restarting app in 5 seconds");
Intent crashedIntent = new Intent(getApplicationContext(), RegisterActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, crashedIntent, 0);
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 5000, pendingIntent);
System.exit(2);
}
};
Within activity onCreate
:
Thread.setDefaultUncaughtExceptionHandler(onCrashRestart);
This is working as expected. But, I have witnessed instances where my app got killed without coming to this handler. I could not see any crash exception in the logs too, that I am maintaining within sdcard of the device.
After trying multiple hacks, I stopped all sqlite database operations within app, this unexpected crash has stopped since.
My question is, are there any known cases where android kills the app and that does not give any exception on crash ?
Also, under what circumstances would android kill an app while running in foreground ?
EDIT: I am using Renderscript apis within my app for Bitmap operations. While running in emulator, following error appears:
09-01 15:04:46.866 4624-9767/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:04:46.878 4624-9758/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:04:46.882 4624-9610/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:04:46.914 4624-9758/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
09-01 15:04:46.934 4624-9781/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83
....
Can this be the culprit ?