Facebook and back button

When using sdk for facebook android to open dialogs, everything works fine.

However, if the user clicks the back button, the dialog does close, but the onCancel method of the dialog listener (or any other method) is not called.

I searched about this question and found this pull request from fb android sdk on github: Call Cancel on DialogListener when the dialog is canceled .

I took one part and slightly modified it to get the following:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        mWebView.stopLoading();
        dismiss();
        mListener.onCancel();
        return true;
    }

    return true;
}

and I added it to the FbDialog class, and it really seems to be a trick.

What I wonder is why this is not part of sdk? This stretch request is more than a year old, and the last answer is about 11 months. Why not add it to the sdk source?

, , facebook sdk, (/ ).

?

+3
2

FbDialog. , , BACK:

setCancelable(false);

BACK:

@Override
public void onBackPressed() {
    mWebView.stopLoading();
    dismiss();
    mListener.onCancel();
}
+6

, SDK , "" DialogListener.

: https://github.com/facebook/facebook-android-sdk/pull/189

:


//call for Fb login dialog
facebook.authorize(this, Constants.FACEBOOK_PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, (DialogListener) new LoginDialogListener());

class LoginDialogListener implements DialogListener{
        public void onComplete(Bundle values) {
            saveCredentials(facebook);
            postToWall();
        }
        public void onFacebookError(FacebookError error) {
            showToast("Authentication with Facebook failed!");
            finish();
        }
        public void onError(DialogError error) {
            showToast("Authentication with Facebook failed!");
            finish();
        }
        public void onCancel() {
            //back button pressed or dialog cancel pressed
            showToast("Authentication with Facebook cancelled!");
            finish();
        }

    }
0

All Articles