There has been instances where we need some code must be executed at the end no matter what happens to the application. Is there any way we can achieve the finally()
functionality in Android?
Note: OnDestroy will not be called during the crash.
For the matter of fact even finally()
is not a full proof method when the JVM exits. But in Java we do not see too many JVM exits. But in android since we have a DVM for every app process, we need a way to execute the final code else, we end up leaking the memory and battery consumption shoots up.