I’m developing an app and I want to put a crash recovery feature, restarting my app. I didn’t write any code related to this.
My idea for this is to start a service that monitors the status. Base on this approach the problem is because service is start from my app, it’ll die if app dies.
Is possible start a service from my app and runs it independently to monitor my app and restart it?
I’m developing an app and I want to put a crash recovery feature, restarting
Share
There are several ways to approach the problem you describe. Perhaps the simplest though is to provide a custom
Applicationclass for your project, and in its onCreate() method, callThread.setDefaultUncaughtExceptionHandler(this);to assign your class as the default exception handler. That will require you to overridepublic void uncaughtException(Thread t, Throwable e)which will be called at the time you crash, and you could schedule a restart.If you really want something outside your process monitoring things, one approach is a service in your application that is defined to have its own process; this is done with an AndroidManifest attribute.
Another option is to use the Android AlarmManager, as that gets handled by the system and can restart your application.