I'm currently serving a kiosk application on a dedicated tablet.
Most of them works well, but in some uncertain cases, an OOM crashed the app.
I use the below library to revive my app with the code inside my Application class.
com.jakewharton:process-phoenix:2.0.0
this.uncaughtException = Thread.UncaughtExceptionHandler { _, e ->
ErrorLogger.saveError(e)
try {
System.gc()
ProcessPhoenix.triggerRebirth(this)
} catch (e: java.lang.Exception) {
ErrorController.showError(e)
} finally {
Runtime.getRuntime().exit(0)
}
}
Thread.setDefaultUncaughtExceptionHandler(uncaughtException)
The app revives but after it, severe lags occur.
When the app starts fresh within a rebooted tablet, it takes the app about three seconds after launch to load everything from the server and internal database. But, after when it launches after OOM, it takes about five minutes to load, as if it's suffering from low memory. AlarmManagers stop working after an ANR of the AlarmManager.
Is there a way to clean the memory or a more fresh way to restart my app?