I want to restart application if there is a crash issue or ram clear or release of memory which will ultimately clear variables and NPE will occur.
I have tried Solution 1 and Solution 2 and,
public class MyApplication extends Application {
private static final String TAG = MyApplication.class.getName();
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Thread.setDefaultUncaughtExceptionHandler(onRuntimeError);
}
/*
* To handle the crash issues, and restart from the last state.
*/
private Thread.UncaughtExceptionHandler onRuntimeError = new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread thread, Throwable ex) {
ex.printStackTrace();
try {
Log.e(TAG, "App crash");
// Try starting the Activity again
Intent intent = new Intent(getApplicationContext(),
SplashScreenActivity.class);
Toast.makeText(getApplicationContext(), "test",
Toast.LENGTH_SHORT).show();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Log.e(TAG, "App crash2");
} catch (Exception e) {
e.printStackTrace();
}
}
};
}
But in all cases neither app restart nor toast message appears, only white screen appears and logs are also printed.
Does ACRA only useful for reporting logs or it also take some extra care of application restarting or preventing ANR?