异常处理和生命周期在Android?生命周期、异常、Android

2023-09-04 13:16:15 作者:戒掉你,戒不掉回忆°

我想学习和Android的测试异常且似乎不能 获取信息过去的try / catch,Thread.currentThread()。setUncaughtExceptionHandler(新MyExceptionHandler())和ACRA。

基本上,我想知道什么时候抛出一个异常,是否只杀了当前的活动会发生什么?如果我的应用程序有多个活动和在第4的活动,在活动的堆栈杀死,它杀死只是一个?

我问,主要是因为我抛出一个错误,它不会杀死完整的程序,但在程序的某些中间活动重新启动它。 (我的目的更多地了解它这样做)我想无论是preFER程序死亡,比重启的一些不好的状态,但 Android有没有杀死开关(至少我所知道的)。

感谢

编辑:如果机器人重新创建堆栈,才能知道有多远一回事呢?或者,如果它使用创建?或恢复?如果有什么在需要的堆栈的用户输入previous活动?

解决方案   

Android有没有杀死开关

您可以尝试System.exit(INT),从Java SE,它可以杀死虚拟机。

  

如果机器人重新创建堆栈,我们知道[...]如果使用创造?或恢复?

的onCreate被称为(见 http://developer.android.com/images/activity_lifecycle.png )

顺便说一句,一个异常不杀程序,但ActivityManager重新启动它。 如果需要的previous活动的用户输入在其上的前活动取决于,应该投入被放入其中开始前活动的意图的捆绑,因为系统节省了捆绑并再次将其传递到活动时重新启动它。

Android学习笔记四 Activity的生命周期

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?

解决方案

Android has no kill switch

You might try System.exit(int), from Java SE, which kills the virtual machine.

If android recreates the stack, do we know [...] if it uses create? or resume?

onCreate is called (see http://developer.android.com/images/activity_lifecycle.png)

BTW, an Exception does kill the program, but the ActivityManager restarts it. If the previous Activities required user input on which the front Activity depends, it should be put into the Bundle which is put into the Intent which starts the front Activity, because the system saves the Bundle and passes it again to the Activity when restarting it.