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

0 Answers0