Search code examples
androidremote-accessremote-debuggingrestart

android-remotely restart application on crash or quit


I am developing a kiosk style android application and it is extremely important to be able to remotely restart the application, or have it somehow autostart itself, should it crash or quit. I know you can easily monitor crashes remotely with tools like BugSense, but is there a way to remotely restart an application once you know it has crashed?

This is a similar question but targeting Windows apps

Best way to detect an application crash and restart it?


Solution

  • You can restart your application using

    System.exit(2)
    

    you can invoke this by sending anything to the mobile app and just use this command

    You can handle uncaught exceptions from a class extended from android.app.applicaton so you forward all exceptions to that class by doing this

    Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler()); 
    

    on creation of the application extended class.

    And the Exception Handler class let it extend an IntentService and implements UncaughtExceptionHandler. That will be called on app crash. Hope this helps