-1

When i use

protected void onPostExecute(String result) {

        if (result.contentEquals("Success")) {
            if(tellAFriend.message.contentEquals("Success")){
                showAlert(TellAFriend.this, getResources().getString(R.string.tell_friend_alert), "1");

    //After showing alertbox clicking ok it has to go to myclass instead of homescreen

            } else if(tellAFriend.message.contentEquals("Failure")){
                if ((language.contentEquals("")) || (language.contentEquals("en"))) {
                    showAlert(TellAFriend.this, Contact.Reason_Eng,"3");
                } else if(language.contentEquals("ar")){
                    showAlert(TellAFriend.this, Contact.Reason_Ar,"3");
                }
            }

        } else {
            showAlert(TellAFriend.this, "Response Failure", "1");
        }

        Dialog.dismiss();

    }




public void showAlert(final Context context, String message,
        final String type) {

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            context);

    // set title
    alertDialogBuilder
            .setTitle(getResources().getString(R.string.app_name));
    language = sharedPreference.getString("language", "");
    if ((language.contentEquals("")) || (language.contentEquals("en"))) {
        alertDialogBuilder
                .setMessage(message)
                .setCancelable(false)
                .setNeutralButton("OK",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                if (type.contentEquals("1")) {
                                    finish();
                                    Intent mainwin = new Intent(context,
                                            MainWindow.class);
                                    startActivity(mainwin);
                                } else if (type.contentEquals("2")) {
                                    finish();
                                    Intent intentList = new Intent(context,
                                            OilTrackerListView.class);
                                    startActivity(intentList);
                                } else if (type.contentEquals("3")) {
                                    dialog.dismiss();
                                }
                                dialog.dismiss();

                            }
                        });

    } else if (language.contains("ar")) {
        alertDialogBuilder
                .setMessage(message)
                .setCancelable(false)
                .setNeutralButton(getResources().getString(R.string.ok),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                if (type.contentEquals("1")) {
                                    finish();
                                    Intent mainwin = new Intent(context,
                                            MainWindow.class);
                                    startActivity(mainwin);
                                } else if (type.contentEquals("2")) {
                                    finish();
                                    Intent intentList = new Intent(context,
                                            OilTrackerListView.class);
                                    startActivity(intentList);
                                } else if (type.contentEquals("3")) {
                                    dialog.dismiss();
                                }
                                dialog.dismiss();

                            }
                        });

    }

    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();
}

Alertbox opens,when i click ok the screen goes to the home screen.I need to open another class instead of homescreen.i was not able to find the showalert.Just now found out.I thought it was an already defined function in android.

zyonneo
  • 1,319
  • 5
  • 25
  • 63

2 Answers2

0

Listener for your OK button in AlertDialogue must be like this.I think you are calling finish() in onClick()

        alert.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

            alert.dismiss();    

        }
        });
Don Chakkappan
  • 7,397
  • 5
  • 44
  • 59
  • I dint do it.....i post some comments....after submit...in the post execute if successful it displays alertbox with neutralbutton by using showalert ,ethod in android.. – zyonneo Mar 09 '15 at 06:57
0

I think i have to change here

if (type.contentEquals("1")) {
                                finish();
                                Intent mainwin = new Intent(context,
                                        whichclassiwant.class);
                                startActivity(mainwin);
                            } 
zyonneo
  • 1,319
  • 5
  • 25
  • 63