I am trying to show the alert dialog in the if condition.
ObdGatewayService.java
public class ObdGatewayService{
if(e.getMessage().equals("Broken pipe")){
((MainActivity) ctx).OBDreconnect();
}
}
MainActivity.java
public void OBDreconnect() {
if(!show_obd_reconnect_dialog) {
AlertDialog.Builder build = new AlertDialog.Builder(this);
build.setMessage(R.string.obd_losted)
.setCancelable(false)
.setPositiveButton("Reconnect", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startLiveData();
}
})
.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});
show_obd_reconnect_dialog = true;
build.show();
}
}
getting error below :
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()