I am creating a Launcher. Sometimes I have errors and of course I have to fix them but I am trying to use an UncaughtExceptionHandler for my whole app.
To do that I use this class:
public class clsMyApplication 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)
{
try
{ Save a log file with the error and
save preferences indicating there was an error to display the next start up.
}
catch(Exception e)
{
}
//Alarm to restart app:
PendingIntent myActivity = PendingIntent.getActivity(clsMyApplication.this, 192837, new Intent(clsMyApplication.this, clsMyMainActivity.class), PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 5000, myActivity );
System.exit(2);
// re-throw critical exception further to the os (important)
defaultUEH.uncaughtException(thread, ex);
}
};
public clsMyApplication()
{
defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
// setup handler for uncaught exception
Thread.setDefaultUncaughtExceptionHandler(_unCaughtExceptionHandler);
}
}
I also add this class to the manifest like this:
<application
android:name=".clsMyApplication"
....
But I still get the Android Exceptions. I am not able to get them using this class. Any help?