Possible Duplicate:
Using global exception handling with “setUncaughtExceptionHandler” and “Toast”
I have implemented UncaughtExceptionHandler
in onCreate()
in one of my activities.
In uncaughtException()
method I am trying to open another activity ErrorActivity
with an extra parameter (error msg and stacktrace). That activity should only show (ment globaly) AlertDialog
and handle logs etc.
Can some one tell me why the ErrorActivity
doesnt open while the code in oncoughtException
gets executed? I suspect the problem is Thread
related.
Here is my first activity (simulating exception in onCreate()
)
public class MainActivity extends Activity {
GlobalSettings settings;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(
new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Intent intent = new Intent(MainActivity.this,
ErrorActivity.class);
Bundle bundle = new Bundle();
bundle.putString("ERROR", ex.getMessage());
intent.putExtras(bundle);
startActivity(intent);
}
} );
settings = (GlobalSettings) getApplication();
settings = null;
settings.getApplicationContext();
setContentView(R.layout.main);
}
}
And my second activity that should handle errors:
public class ErrorActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
String name = bundle.getString("ERROR");
ShowAlertDialog(name);
}
}