I have implemented default exception thread handler in application as follows
public class ExceptionHandler implements Thread.UncaughtExceptionHandler {
private Context context;
private Class<?> activity;
public ExceptionHandler(MobileTechnicianApp mobileTechnicianApp, Class<?> activityClass) {
context=mobileTechnicianApp.getApplicationContext();
activity=activityClass;
}
@Override
public void uncaughtException(Thread thread, Throwable exception) {
if(Validator.isNotNull(activity)) {
Intent intent=new Intent(context,SplashScreenActivity.class);
intent.putExtra(Constants.CRASH_BUNDLE_KEY,"crash");
context.startActivity(intent);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
}
}
below is the code for SplashScreen.
public class SplashScreenActivity extends GlobalActivity implements Responselistner {
WeakHandler weakHandler;
private AVLoadingIndicatorView progressView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
weakHandler=new WeakHandler();
progressView= (AVLoadingIndicatorView) findViewById(R.id.text_dot_loader);
progressView.setVisibility(View.VISIBLE);
progressView.show();
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
if(Validator.isNotNull(getIntent().getStringExtra(Constants.CRASH_BUNDLE_KEY))){
if(Validator.isNotNull(getIntent().getStringExtra(Constants.CRASH_BUNDLE_KEY))){
Request.makeJsonObjectRequest(Constants.URL_GET_REQUEST_STATUS,this, RequestParameterBuilder.buildParameterforRequestStatus());
}
else {
Log.d("token","else");
}
}
else {
weakHandler.postDelayed(new Runnable(){
@Override
public void run() {
if (MobileTechnicianApp.preferences.getBoolean(Constants.PREFERENCE_MOBILE_NUMBER_VERIFIED_KEY, false)) {
redirect(ActivityOne.class);
} else {
redirect(AuthenticationOneActivity.class);
}
}
}, 5000);
}
}
and for test i throws a null pointer exception to test it from another activity.but after crash it is not restart flow from splash screen although i have set to redirect to splash screen. i am not able to identify where i have done mistake.Any help is appreciated.