Karly
Karly

Reputation: 389

Quitting alertdialog after a startactivity

I have a method that displays and AlertDialog that has 3 Buttons; neutral, negative and positive.

I want the neutral to open the contacts application in front of my application with a Dialog. However, the Dialog is shut when i come back to my Activity even though it is supposed to be "neutral" and i did not put any return statement.

Here is my code:

    public static void showAddFriendDialog(Context ctx1) {
        final Context ctx = ctx1;

        //showGetFriendsFromContacts(ctx);

         // Set an EditText view to get user input 

         final EditText input = new EditText(ctx); input.setHint("name");
         final EditText input2 = new EditText(ctx); input2.setHint("firstname");
         final EditText input3 = new EditText(ctx); input3.setHint("login/email");

         // on est obligé de mettre un layout car on peut que mettre un setview
         LinearLayout layout = new LinearLayout(ctx);
         layout.setOrientation(LinearLayout.VERTICAL);

         layout.addView(input);
         layout.addView(input2);
         layout.addView(input3);

         AlertDialog.Builder builder = new AlertDialog.Builder(ctx);

         builder.setCancelable(true);
         builder.setTitle("Add a friend");
         builder.setMessage("Fill in the fields you know or get your contact info from your Contact List :");

         builder.setView(layout);

        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

........................

            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                return;
            }
        });

        builder.setNeutralButton("Contact List",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                        ctx.startActivity(new Intent(null, ContactsContract.Contacts.CONTENT_URI));

                    }

       });


        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                return;
            }
        });

        builder.show();
    }

Does someone know what is causing that ?

Upvotes: 0

Views: 103

Answers (1)

Erol
Erol

Reputation: 6526

Default dialogs will always quit when a button is clicked no matter what.

It is recommended for you to implement your custom dialog to avoid that.

Upvotes: 1

Related Questions