How can I notify another application that my application has failed?
<p>In my application, I start an activity, that is in another application (Eclipse project) the following way:</p>

<pre><code>Intent intent = new Intent();
intent.setAction(game.getLaunch());
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(intent, game.getId());
</code></pre>

<p>If this second application is finished, I call:</p>

<pre><code>MySecondApplication.this.setResult(getGameId());
MySecondApplication.this.finish();
</code></pre>

<p>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:</p>

<pre><code>Thread.setDefaultUncaughtExceptionHandler(handler);
</code></pre>

<p>This works fine, in the method</p>

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

<p>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?</p>

<p>EDIT #1:</p>

<p>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.</p>

<p>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?</p>

<p>EDIT #2:</p>

<p>I was able to close the second activity by calling:</p>

<pre><code>((Activity) context).finish();
</code></pre>

<p>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?</p>
