Failure after crashing on the UI thread

I have implemented UncaughtExceptionHandler

in my Android code. If an error occurs, it logs some diagnostic data first, then it tries to exit. I have completed the recipe in How to kill an application with all its actions? to close the actions in cascade.

This works when the error is on a non-UI thread, or when the main activity is active. However, if the error occurred on the UI thread in a subactivity, the calling activity never wakes up. onActivityResult()

is never called and the application hangs. Is there a way to crash after a UI thread crash?

Here's a simplified version:

public void uncaughtException( final Thread t, final Throwable e )
{
    Activity ac = currentActivity();
    ac.setResult( 99 );
    ac.finish();
}

      

in the main action:

public boolean onOptionsItemSelected(MenuItem item)
{
    Intent intent = new Intent( getApplicationContext(), SettingsActivity.class );
    startActivityForResult( intent, 0 );
}

protected void onActivityResult( int rqC, int resultCode, Intent data )
{
    if ( resultCode == 99 )
    {
        setResult( 99 );
        finish();
    }
    super.onActivityResult( rqC, resultCode, data );
}

      

+3


source to share





All Articles