Hello Vasiliy :)
Fábio Carballo
1

For example, you can have the following method in your Activity:

public void onSomeEvent() {
doSomething();
doSomethingElse();
}

Application’s logic assumes that after this method returned both doSomething() and doSomethingElse() were called and their side effects occurred. This is called invariant.

However, if the exception is thrown from doSomethingElse() then only the side effects of doSomething() are guaranteed to occur.

If the app crashes, then all the (non-persistent) state will be cleared. Ugly, but relatively safe.

The technique you proposed will restart the Activity, but will not clear the state. Therefore, the restarted Activity can potentially observe the side effects of doSomething() without the side effects of doSomethingElse() .

This is called invariant violation and, as I said, it can lead to totally unpredictable behavior.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.