3

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 ?

jay
  • 1,982
  • 2
  • 24
  • 54
  • Does it show 'Unfortunately app has stopped' popup? – j2ko Sep 01 '16 at 18:21
  • No, that's the weird part. If it does, then it would come to the handler mentioned above. – jay Sep 01 '16 at 18:24
  • It's possible the app is crashing in native code. Check the unfiltered logcat for a native crash dump. Java exceptions don't apply there. – Larry Schiefer Sep 01 '16 at 19:38
  • @LarrySchiefer - Sir, I think you are right, can you please please give some more information in this regard ? – jay Sep 01 '16 at 19:42
  • 1
    Please also note that first `ContentProvider.onCreate()` is called then `Application.onCreate()` and finally the `Activity.onCreate()`. So if you initialize the `UncaughtExceptionHandler` in `Activity.onCreate()` then it can happen that the app will crash before you can initialize it. – Blehi Sep 01 '16 at 19:43
  • @Blehi - The app crashes after being run fine for more than few minutes (30-40). So, I think its not crashing in the earlier methods. But, thanks for the information :). – jay Sep 01 '16 at 19:45
  • If using Android Studio, switch logcat view to be unfiltered. Or, run `adb logcat` from the command line, assuming adb is in your path. It can be found in your Android SDK under the `platform-tools` directory. Unfortunately, if it is a native crash you will likely have little or no symbol data to work from. – Larry Schiefer Sep 01 '16 at 19:45
  • 09-01 15:05:15.198 4624-10128/? E/RenderScript: rsAssert failed: ret == bytes || mShutdown, in frameworks/rs/rsFifoSocket.cpp at 83 (this line comes many times, eventually crash happens). Possibly this ? – jay Sep 01 '16 at 19:51

1 Answers1

0

App if crashing in native code, Java exception do not apply. Usage of Renderscript support library in one such instance. Often times, these are difficult to debug.

Read - Catching exceptions thrown from native code running on Android on handling the same.

Community
  • 1
  • 1
jay
  • 1,982
  • 2
  • 24
  • 54