4

I want to start a new activity from my UncaughtExceptionHandler when an uncaught exception appears. Is this possible?

I think the current activity can't start a new child activity in its "error" state because I always get this errors:

07-14 14:34:06.075: INFO/ActivityManager(74): Starting activity: Intent { flg=0x10000000 cmp=de.rwth/system.ErrorHandler (has extras) }
07-14 14:34:06.615: WARN/ActivityManager(74): Activity pause timeout for HistoryRecord{4338f8d8 de.rwth/.main}
07-14 14:34:16.115: WARN/ActivityManager(74): Launch timeout has expired, giving up wake lock!
07-14 14:34:16.628: WARN/ActivityManager(74): Activity idle timeout for HistoryRecord{433a89d8 de.rwth/system.ErrorHandler}

I tried to start the child activity from a new thread, because i thought the current thread might be in a state where it is not allowed to start a new activity but this didn't work too.

So does anyone know how this could work? How do i prevent the current activity from blocking everything while in this error state? is the any way to set the exception to handled?

Macarse
  • 91,829
  • 44
  • 175
  • 230
Simon
  • 13,173
  • 14
  • 66
  • 90
  • Launching an application from an `ExceptionHandler` is wrong. – Macarse Jul 14 '10 at 14:06
  • What if we just want to present the user to email the exception output. How so? – Pentium10 Jul 14 '10 at 14:14
  • I want to display a new activity (or anything else i can set a layout to) with the errorlog so how can i do this? the default error handler does show a error message to so it must be possible. maybe the problem is that the new activity is a subactivity from the current (broken) activity and wont display because of this? – Simon Jul 14 '10 at 16:12

1 Answers1

5

What you will need to do is specify your exception display Activity in your manifest file and set android:taskAffinity and android:process to values different from your main process. Then you'll need to specify an intent filter and use that to start the activity and pass the data.

By default the taskAffinity is inheried from the main <application> tag and is the same page name set in the <manifest> tag. You probably want something like android:taskAffinity="org.example.package.TASK.ExceptionDisplay"

By default everything in one <application> tag runs in the same process. You can change that using the android:process attribute you probably want something like android:process=":exception_process".

Check out this documentation for more details.

Rich Schuler
  • 41,814
  • 6
  • 72
  • 59
  • what do i have to set android:taskAffinity and android:process to? I understand the part with the intent filter but i dont know what these two parameters do.. my intent filter works for the calling intent and looks like this: – Simon Jul 16 '10 at 12:49
  • this is really great, seems like it works now :) thanks a lot. i had an other question in the meanwhile about remote services ( http://stackoverflow.com/questions/3269176/activity-crashes-when-remote-service-crashes ). it seems that you know this part of android very well, maybe you know the answer to this too;) services dont have a affinity attribute and im not shure how to seperate them from the calling activity – Simon Jul 17 '10 at 00:04