tags:

views:

49

answers:

1

In my application, I start an activity, that is in another application (Eclipse project) the following way:

Intent intent = new Intent();
intent.setAction(game.getLaunch());
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(intent, game.getId());

If this second application is finished, I call:

MySecondApplication.this.setResult(getGameId());
MySecondApplication.this.finish();

This works fine if the second application is terminated normally. But I would like to catch any uncaught exception in the second application and notify the first application that the second application has failed. Therefore I tried to use a UncaughtExceptionHandler in my second application:

Thread.setDefaultUncaughtExceptionHandler(handler);

This works fine, in the method

@Override
public void uncaughtException(Thread thread, Throwable ex) {
 System.out.println("Exception in my second application");
}

However, I can't do there anything more, than making a sysout. If I tried to do something more complex like e.g. an alert dialog, or somehow alert the first application, all this isn't called. I think this is because the second application was already terminate because of the exception. But how can I then notify my first application that the second has terminated unforeseenly? Any hints?

EDIT #1:

With the help of pentium10 i was able to notify the first application that the second has crashed by sending a broadcast to the first application in the uncaugthExceptionHandler. It wasn't necessary to do this process id stuff in the question he linked.

However, my problem isn't yet solved completely: I can notify my first application, but my second application where the exception happened is not really "terminated". It is just a black screen. So how can i solve this?

EDIT #2:

I was able to close the second activity by calling:

((Activity) context).finish();

where context is the second activity. However, now it takes a long time until the broadcast intent from the second activity is received by the first activity. Approximately it takes 30 or even more seconds. Why does this take so long?

+2  A: 

You need to issue a broadcast or start some service to notify it.

This other question will help you it's about starting activity on uncaughtException() call

Pentium10
Thanks this seems very helpful. Do you know if I can use broadcast without doing this process id thing in the question you linked? (for sure I could try it, but if you know it already, i can save a lot of time ;) )
Roflcoptr
I don't have experience with it. Please post back your findings so we should know how this can be accomplished.
Pentium10
Thanks, I edite my question.
Roflcoptr
Again, I edited my question ;)
Roflcoptr
That's cool, but I don't know the question. And you should ask new questions for different problems. Anyway change the broadcast to something else like toast, starting an activity, starting a service and see if that loads in delayed.
Pentium10