Is there a way to exit android application from the Application class itself. This is even before any activity has been initialized.
Scenario is user side-loading the build in an unsupported device which leads to crashes when I try to load third-party library not meant for the device.
This loading of third-party SDK happens in the application class.
Is it safe to use System.exit(0) in this case since I cannot call finishAffinity()?
Quick answer: You can use any of the functions to exit an app mentioned in this post. You can call your exit function in the onCreate()
function of your Application class. However, all of them will result to a flicker in unsupported devices. This is not a graceful way to exit an app.
Preferred answer: So, as an alternative, show an activity that explains why the app can't continue to load. If it is possible, move your library loading in another class. Use its return value to determine if the loading happened successfully. If successful, continue loading else show an error message then exit the app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With