用户凭据对话框不会被忽略,但正在等待其他服务

时间:2012-08-27 21:13:38

标签: android view dialog dismiss

我在对话框中遇到问题,用户可以输入密码和用户名。用户帽输入数据并单击“确定”后,此对话框不会被忽略。

这是对话框:

private void askUserCredentials(String pWarning) {
        // starting the user credentials
        Log.v(tag, "askUserCredentials started ");

        // create the new dialog
        final Dialog dialogCredentials = new Dialog(this);

        //Set the content view to our xml layout
        dialogCredentials.setContentView(R.layout.dialog_login);

        // if there is a warning
        if (pWarning != null) {
            // show it instead of the regular text
            TextView dialogDescription = (TextView) dialogCredentials
                    .findViewById(R.id.dialog_cred_description);

            dialogDescription.setText(pWarning);

            // also set it to red
            //dialogDescription.setTextColor(R.color.text_headline_main);
        }

        // Set the title of the dialog. this space is always drawn even if blank
        // so might as well use it
        dialogCredentials
                .setTitle(getString(R.string.LABEL_DIALOG_CREDENTIALS));

        // get password and username
        String lUsername = SharedPrefHandler.getPrefString(
                getApplicationContext(), SharedPrefHandler.USER_NAME);
        String lPassword = SharedPrefHandler.getPrefString(
                getApplicationContext(), SharedPrefHandler.USER_PASSWORD);

        // to get the values later set the reference to the fields
        final EditText txtPassword = (EditText) dialogCredentials
                .findViewById(R.id.edit_text_password);
        final EditText txtUsername = (EditText) dialogCredentials
                .findViewById(R.id.edit_text_username);

        // preset the values
        if (lUsername != null)
            txtUsername.setText(lUsername);
        if (lPassword != null)
            txtPassword.setText(lPassword);

        // Allow the dialog to be cancelable
        dialogCredentials.setCancelable(true);

        Button okButton = (Button) dialogCredentials
                .findViewById(R.id.dialog_cred_butt_OK);
        Button canceButton = (Button) dialogCredentials
                .findViewById(R.id.dialog_cred_butt_cancel);

        okButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Log.v(tag, "Got some data - username:"
                        + txtUsername.getText().toString() + "-Password: "
                        + txtPassword.getText().toString());

                //close the dialog
                dialogCredentials.dismiss();

                // store them to the users settings
                SharedPrefHandler.storeSharedPref(getApplicationContext(),
                        txtUsername.getText().toString(),
                        SharedPrefHandler.USER_NAME);
                SharedPrefHandler.storeSharedPref(getApplicationContext(),
                        txtPassword.getText().toString(),
                        SharedPrefHandler.USER_PASSWORD);

                guiStatusMessage.setText("#Bitte warten.");

                //Start the sync in case the user just entered the credentials
                startSynchronisation();

                Log.i(tag,"started synch!"); //gets called after the function was executed
            }
        });

        // close the dialog if canceled
        canceButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                dialogCredentials.dismiss();

            }
        });

        dialogCredentials.show();
    }

用户输入凭据后,会点击“确定”按钮。一切正常,但命令“startSynchronisation()”可能需要一段时间,对话框不会被解雇。同步正在另一个服务中运行,因此完全不清楚对话框为什么会等待它。

private void startSynchronisation() {


        try {
            if (myServerServiceBound && myServerService != null)

                myServerService.IgetUserData();
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

非常感谢。它必须是架构问题,因为我在另一段代码中也有类似的问题。那里的Optionsmenue没有关闭。

由于

1 个答案:

答案 0 :(得分:0)

缺少的东西是ONEWAY将异步调用设置为远程进程。

花了一会儿找到那个....