I am facing a weird (in my opinion) issue. My app rarely produces ANRs. I am trying to reduce them wherever possible and i have been succesful so far. However, when the ANR dialog does appear, if i (or any user) decide to close the app by pressing "close app" rather than wait for it to get responsive, then the app closes but immediately gets relaunched displaying the same activity as it did when the ANR dialog got displayed.
This is troublesome because when a user normallly starts my app there is a certain sequence of activities he/she passes through, each responsible to perform some tasks, create some objects etc. When the app gets automatically relaunched however and the user finds himself in the same activity he was when the ANR dialog got displayed, this sequence of activities has not taken place, so certain things required are missing and thus my app crashes. It might be that an object is null, an int has wrong value than it should, some string may be empty etc. The exact problem is not important here. The important thing is that the app has not gone through the sequence of activities that it normally does when opened by a user , setting up all those objects,variables etc that it will later need before reaching this activity.
On the other hand, if my app crashes at any point, i have an UncaughtExceptionHandler that closes my app in a "clean way". The equivalent of a user pressing the "Overview" button and then closing the app either by pressing "x" or by swiping it left/right. So if the user wants to use the app again, he/she launches it again, the app goes through the sequence of activities it should and everything works as intended. However when an ANR dialog appears, i cannot control what pressing "Close App" actually does...
Or can i?
Is this the correct behaviour of the ANR dialog or am i missing something here? Has anyone else ever experienced this? Is there any way i can make my app close and stay closed after the user has selected the "Close app" option in the dialog? (I am guessing not).
Thank you in advance and please, if i am missing something obvious here, try to be gentle! :)