0
votes

I have question regarding the option to automatically restart an android based app if an uncaught exception is fired causing the application to quit. My idea for implementing this request is as follows,

  1. Create a PendingIntent in the OnCreate function of the MainLauncher. Would this PendingIntent point to a BroadCastReceiver in this case which could then fire off the MainLauncher Activity to restart the app?

    protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); restartIntent = PendingIntent.GetActivity(this, 0, new Intent(this, typeof(aBroadcastReceiverMaybe)), 0); }

  2. Catch any uncaught exceptions for my app. My understanding is you could possibly override a function Thread.setDefaultUncaughtExceptionHandler() but this is in Java implementation for android. I am not quite sure how this works in under the xamarin framework

  3. In the uncaught exception override, create an AlarmManager which will fire the PendingIntent from step 1 after 4 seconds. Force quit the app using an exit() function, again unsure of implementation under xamarin framework.

  4. After 4 second delay in step 3, BroadcastReceiver will be notified. On Receiving notice, fire up MainLauncher Activity to restart app.

If there is a more suitable implementation for this task I would be happy to take onboard. Look forward to hearing from you soon.

1

1 Answers

2
votes

You'd better off handling the errors mate. As a user if I have a buggy app on my phone and every time it crashes it automatically restarts it is only gonna become an annoyance.