manf
manf

Reputation: 55

Closing a AlertDialog without pressing a Button

I want to establish a connection via Socket to a Server, while the phone is trying to establish the connection i want to bring up an AlertDialog to front without buttons that will be closed when the connection is established.

private void attempToSendXML(AlertDialog.Builder builder, String profile) {
    SocketClient client = new SocketClient();
    Alerts.establishConnection(builder);
    connectionEstablished = client.createClient(server, port);
    //Close the Dialog here!
    if (!connectionEstablished) {
        connectionRefusedAlert(builder);
        return;
    }

Upvotes: 3

Views: 938

Answers (2)

Ben Weiss
Ben Weiss

Reputation: 17960

In order to remove your Dialog correctly you should call mDialog.dismiss();.

Upvotes: 0

Tom van der Woerdt
Tom van der Woerdt

Reputation: 29985

You may want to read the section in the manual on Process Dialogs. They too are alert dialogs.

http://developer.android.com/guide/topics/ui/dialogs.html#ProgressDialog

AlertDialog.Builder returns an object that has a .close() function. Use that to close the dialogs.

Upvotes: 1

Related Questions