Android : How to wait for an okay button before starting a new activity

on Saturday, September 20, 2014


Good day.I have a problem, I am displaying a message box when a button is clicked.The message box simple shows a confirmation of registration.After that I open a new activity. The problem is that it shows the messagebox and then starts the new activity without waiting for the ok button to be clicked.How can I only display the new activity upon clicking the ok button.


Below is the code I used.



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);

Button btn = (Button)findViewById(R.id.registerButton);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), BookingActivity.class);
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(context);

dlgAlert.setMessage("You have successfully Registered.Please Press okay to continue");
dlgAlert.setTitle("Registration");
dlgAlert.setPositiveButton("OK", null);
dlgAlert.setCancelable(false);
dlgAlert.create().show();


startActivity(intent);
finish();
}
});

0 comments:

Post a Comment