android - Is it impossible to start a Activity in UncaughtExceptionHandler -
i found not works when start new activity in uncaughtexceptionhandler. mean not show annoying android crash dialog. on other hand, want start new activity indicate user encounter serious error, u wanna quit or continue use app still possibility weird may happen.
i try restart app in uncaughtexceptionhandler
final intent intent = getpackagemanager().getlaunchintentforpackage(getpackagename()); intent.addflags(intent.flag_activity_clear_top); startactivity(intent);
but, i'm in bad luck again. not work either...
i tried restart app after crashed happens. catched uncaught exceptions in application extension class. in exception handler exception , try set alarmmanager restart app. here example how in app, log exception db.
public class myapplication extends application { // uncaught exception handler variable private uncaughtexceptionhandler defaultueh; // handler listener private thread.uncaughtexceptionhandler _uncaughtexceptionhandler = new thread.uncaughtexceptionhandler() { @override public void uncaughtexception(thread thread, throwable ex) { // here logging of exception db pendingintent myactivity = pendingintent.getactivity(getcontext(), 192837, new intent(getcontext(), myactivity.class), pendingintent.flag_one_shot); alarmmanager alarmmanager; alarmmanager = (alarmmanager)getsystemservice(context.alarm_service); alarmmanager.set(alarmmanager.elapsed_realtime_wakeup, 15000, myactivity ); system.exit(2); // re-throw critical exception further os (important) defaultueh.uncaughtexception(thread, ex); } }; public myapplication() { defaultueh = thread.getdefaultuncaughtexceptionhandler(); // setup handler uncaught exception thread.setdefaultuncaughtexceptionhandler(_uncaughtexceptionhandler); } }
Comments
Post a Comment