In an Android application, we usually got the "Force Closed" error if we didn’t handle the exceptions properly.
How can I restart my application automatically if it is force closed?
Is there any specific permission used for this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To accomplish this you have to do two things:
See below how to do these:
Call
Thread.setDefaultUncaughtExceptionHandler()in order to catch all uncaught exception, in which caseuncaughtException()method will be called. “Force close” will not appear and the application will be unresponsive, which is not a quite good thing.In order to restart your application when it crashed you should do the following :
In the
onCreatemethod, in your main activity initialize aPendingIntentmember:Then put the following in your
uncaughtException()method:You also must call
System.exit(), otherwise will not work.In this way your application will restart after 2 seconds.
Eventually you can set some flag in your intent that the application crashed and in your
onCreate()method you can show a dialog “I’m sorry, the application crashed, hope never again :)”.