Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception handling and lifecycle on Android?

Tags:

android

I am trying to learn and test exceptions in android and can't seem to get information past try/catch, Thread.currentThread().setUncaughtExceptionHandler(new MyExceptionHandler()) and ACRA.

Basically I want to know what happens when an Exception is thrown, does it kill only the current activity? What if my application has multiple activities and its killed in the 4th activity that is in the stack of activities, does it kill just the one?

I ask mainly because I am throwing an error and its not killing the complete program but restarting it at some middle activity of the program. (I am doing this on purpose to learn more about it) I would either prefer the program dies, than restart in some bad state, but Android has no kill switch (at least that I know of).

Thanks

EDIT: If android recreates the stack, do we know how far it goes? or if it uses create? or resume? What if the previous activities in the stack needed user input?

like image 479
Totic Avatar asked Mar 24 '11 11:03

Totic


1 Answers

What I have observed from the LogCat is that android sort of caches the intents and tries to re-construct your stack from those. What I mean is, say you activity stack consists of Activity A, B, C, D (D on top, A at bottom) and an exception is thrown in Activity D. Then the OS tries to reconstruct the stack by firing intents for A, then B and then C. But I'm not sure about it

like image 53
pankajagarwal Avatar answered Sep 18 '22 23:09

pankajagarwal