Reputation:
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?
Upvotes: 0
Views: 191
Reputation: 207912
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
Upvotes: 2