I’m opening an Activity using this:
startActivity(new Intent(Parent.this, Child.class));
And on the child, I have this code on the onCreate function (the if contains more than just true, of course):
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (true) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setPositiveButton("OK", null);
builder.setTitle("Error");
builder.setMessage("Connection error, please try later.")
.show();
finishActivity(0);
return;
}
}
Why is the activity not closing? I get the alert box, but then I have to tap the “back” button to go back.
Try using the finish() method to close the Activity.