1

I have a problem trying to handle the force closes of my Android app that I can't solve. My idea was to show a customize message when some uncontrolled exception happens.

Here's my code:

public class ManejadorExcepcionesUnhandled implements Thread.UncaughtExceptionHandler{

    private Context contexto;
    private Activity activityactual;
    public ManejadorExcepcionesUnhandled(Activity app) {
        activityactual = app;
        contexto = app;
        Thread.getDefaultUncaughtExceptionHandler();

    }

    public void uncaughtException(Thread t, Throwable e)
    {

        new Thread() {
            @Override
            public void run() {
                Looper.prepare();
                new AlertDialog.Builder(contexto).setTitle("Se ha producido un error.").setCancelable(false)
                        .setMessage("Si el problema persiste contacte con ----------.").setNeutralButton("OK", new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {


                                android.os.Process.killProcess(android.os.Process.myPid());
                                System.exit(10);
                            }
                        })
                        .create().show();
                Looper.loop();
            }
        }.start();


    }
}

This code works in most of devices I tried, but with a smartphone with 2.2.2, it justs show a black screen when the app is restarted. What do I have to do? Can't this run in all devices?

Sr_Evax
  • 9
  • 3
  • 2
    That actually works on some devices? – zapl Feb 19 '14 at 15:33
  • that cannot work. `getDefaultUncaughtExceptionHandler` does only return the current exception handler. you need to `setDefaultUncaughtExceptionHandler` – njzk2 Feb 19 '14 at 15:40
  • @njzk2, in my activities, I use Thread.setDefaultUncaughtExceptionHandler(new NS.Android.Excepciones.ManejadorExcepcionesUnhandled(this)); – Sr_Evax Feb 19 '14 at 15:47
  • @Sr_Evax : may be that was worth mentioning. – njzk2 Feb 19 '14 at 15:52
  • See http://stackoverflow.com/questions/2764394/ideal-way-to-set-global-uncaught-exception-handler-in-android/ – fadden Feb 20 '14 at 01:51

0 Answers0