0

I want to know how to execute any function completely before moving to next coding statements.

    public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.btnBack:
        i = new Intent(SetUpActivity.this, HomeActivity.class);
        finish();
        break;
    case R.id.btnOne:
        showDisclaimerDialog();
        Log.d("agreed value", agreed+"");
        if (agreed) {
            Log.e("Inside", "btnOne");
            appObj.setMaxFeeds(1);
            i = new Intent(SetUpActivity.this, SelectFeedsActivity.class);
            startActivity(i);
        }
        break;
    case R.id.btnTwo:
        showDisclaimerDialog();
        if(agreed) {
            appObj.setMaxFeeds(2);
            i = new Intent(SetUpActivity.this, SelectFeedsActivity.class);
            startActivity(i);
        }
        break;
    case R.id.btnFive:
        showDisclaimerDialog();
        if (agreed) {
            appObj.setMaxFeeds(5);
            i = new Intent(SetUpActivity.this, SelectFeedsActivity.class);
            startActivity(i);
        }
        break;

    default:
        break;
    }


private void showDisclaimerDialog() {
    // TODO Auto-generated method stub
    AlertDialog.Builder builder = new AlertDialog.Builder(
            SetUpActivity.this);
    builder.setTitle("Disclaimer");
    builder.setMessage(Html.fromHtml(getString(R.string.disclaimer)));
    builder.setPositiveButton("I Agree",
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    agreed = true;
                    Log.e("Inside I agree",agreed+"");
                }
            });
    builder.setNegativeButton("Cancel",
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    agreed = false;
                    Log.e("Inside Cancel",agreed+"");
                }
            });

    builder.create().show();
    agreed=false;
    Log.e("Inside dialog",agreed+"");

}

When I click on "btnOne" , the control of the execution should go to "showDiclaimerDialog()" without executing further statments which are

        Log.d("agreed value", agreed+"");
    if (agreed) {
        Log.e("Inside", "btnOne");
        appObj.setMaxFeeds(1);
        i = new Intent(SetUpActivity.this, SelectFeedsActivity.class);
        startActivity(i);
    }
Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57

1 Answers1

1

You can't(as in you can but really really really shouldn't) block execution in the GUI thread. See this question for details.

Dialogs / AlertDialogs: How to "block execution" while dialog is up (.NET-style)

Community
  • 1
  • 1
dutt
  • 7,909
  • 11
  • 52
  • 85
  • Yeah! Thanks a lot for the suggestions but is there any way to execute multiple functions but only one after another?because I require the solution in another part of code also.I want to call two functions one by one.like first(); second(); – Mehul Joisar Sep 26 '12 at 08:06
  • Yep, like Michael Laffargue said. Put it in the onClick of the dialog instead. – dutt Sep 26 '12 at 09:01