如果出现崩溃问题或ram清除或释放内存最终会清除变量并且NPE将会发生,我想重新启动应用程序。
我尝试了Solution 1和Solution 2以及
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();
}
}
};
}
但是在所有情况下都不会显示应用重启或吐司信息,只会出现白屏并且还会打印日志。
ACRA仅对报告日志有用吗,还是需要额外注意应用程序重启或阻止ANR?