Monday, 17 February 2014

Handle application force close in android

Handle application force close in android

         This is my sample coding is very helpful for you to handle the force close in android applications.


Here,i have crate a force close when click the button,

button1.setOnClickListener(new OnClickListener() {
               @Override
               public void onClick(View v) {
                     //Here App will restart instead of showing force close dialog
                     int i = Integer.valueOf("Android");
                     button1.setText(i);

               }


        });



And,then i have caught the exception using the


Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler(this,  MainActivity.class));



Then,perform your action like restart the activity or anything.


public void uncaughtException(Thread thread, Throwable exception) {
StringWriter stackTrace = new StringWriter();
exception.printStackTrace(new PrintWriter(stackTrace));
Intent intent = new Intent(myContext, myActivityClass);
myContext.startActivity(intent);
System.exit(0);


}






No comments: