0

I currently have an app which launches a different Activity if the user has crashed multiple times. However, the app can still crash in this alternate activity due to background services / push services.

Is there a way to prevent the main thread from dying and still retain its message queue. I am using Thread.setDefaultUncaughtExceptionHandler() and swallowing the exception but seems like the thread still freezes or terminates. I tried thread.start() but then all the UI events that were posted to the MessageQueue no longer work (the view is frozen)

Johnett Mathew
  • 307
  • 1
  • 10
  • 20
cappicone
  • 33
  • 3

1 Answers1

0

I don't think that Thread.start() is enough in this case. If I understood the problem you cannot handle uncaught exceptions anymore after uncaught exception handler. I think the best way is to start your "different Activity" in another process. Here is explained how to do that.

I've copied some sources from that answer. You first prepare pending intent.

intent = PendingIntent.getActivity(/*Applcation context*/, 0,
        /*Intent to 'different activity'*/, /*flags*/);

Then in uncaught exception handler you set up alarm manager for let's say 2 sec.

AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent);
System.exit(2);
Community
  • 1
  • 1
olegr
  • 1,999
  • 18
  • 23