1

I am using Facebook Android SDK to allow SSO. I have followed the guide and the tutorial in Hackbook but it happens that the phone seems stucked on a white screen, after 10 seconds a progress dialog appears and the process continues as expected.

I have tried hard to fix the issue (async tasks, transparent layouts) but it seems nothing is working.

This is the code in facebook activity:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.facebook_activity);
    /*
     * Get existing access_token if any
     */
    mPrefs = getPreferences(MODE_PRIVATE);
    String access_token = mPrefs.getString("access_token", null);
    long expires = mPrefs.getLong("access_expires", 0);
    if (access_token != null) {
        facebook.setAccessToken(access_token);
    }
    if (expires != 0) {
        facebook.setAccessExpires(expires);
    }

    /*
     * Only call authorize if the access_token has expired.
     */
    // showProgress();
    if (!facebook.isSessionValid()) {

        authorizeFacebook();
    } else {
        signalResult();
    }
}


private void authorizeFacebook() {
    facebook.authorize(this, new String[] { "email", "offline_access",
            "publish_stream", "user_about_me" }, new DialogListener() {
        @Override
        public void onComplete(Bundle values) {
            // SharedPreferences.Editor editor = mPrefs.edit();
            // editor.putString("access_token",
            // facebook.getAccessToken());
            // editor.putLong("access_expires",
            // facebook.getAccessExpires());
            // editor.commit();
            signalResult();
            // retrieve call obtain information and register

        }

        @Override
        public void onFacebookError(FacebookError error) {
        }

        @Override
        public void onError(DialogError e) {
        }

        @Override
        public void onCancel() {
        }
    });
}

private void signalResult() {
    // retrieve user info
    new AsyncFacebookRunner(facebook).request("me",
            new AsyncFacebookRunner.RequestListener() {

                @Override
                public void onMalformedURLException(
                        MalformedURLException e, Object state) {
                    authorizeFacebook();
                }

                @Override
                public void onIOException(IOException e, Object state) {
                    authorizeFacebook();
                }

                @Override
                public void onFileNotFoundException(
                        FileNotFoundException e, Object state) {
                    authorizeFacebook();
                }

                @Override
                public void onFacebookError(FacebookError e, Object state) {
                    authorizeFacebook();
                }

                @Override
                public void onComplete(String response, Object state) {
                    Intent intent = new Intent();
                    String accessToken = facebook.getAccessToken();
                    String id = null;
                    JSONObject json;
                    try {
                        json = new JSONObject(response);
                        id = json.getString("id");
                        intent.putExtra(WeOrderApplication.FACEBOOK_USER, id);
                        intent.putExtra(WeOrderApplication.FACEBOOK,
                                accessToken);
                        // hideProgress();
                        setResult(RESULT_OK, intent);
                        finish();
                    } catch (JSONException e) {
                        authorizeFacebook();
                        e.printStackTrace();
                    }

                }
            });

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    facebook.authorizeCallback(requestCode, resultCode, data);
}

and it is called through a simple StartActivity. facebook_activity is a linearLayout without anything in it. I have set a translucent theme (android:theme="@android:style/Theme.Translucent.NoTitleBar") to FacebookActivity to make it at least transparent but it didn't work either.

Thanks to anyone that could help fixing this.

Matroska
  • 6,885
  • 14
  • 63
  • 99

2 Answers2

0

I think that this may be because both facebook.authorize() and signalResult() are running asynchronously. The code needs to first call to authorize, but then needs to wait on the network for that call to finish before starting the intent. This might pause the application.

Alternately, since all your error states recall authorizeFacebook(), and each one of those requests are asynchronous, is it possible that you have a number of threads all being spun out at once?

biegleux
  • 13,179
  • 11
  • 45
  • 52
ZenBalance
  • 10,087
  • 14
  • 44
  • 44
0

Please update below code of your authorizeFacebook() function, it will solve your problem.

facebook.authorize(mActivity, mPermissions, Facebook.FORCE_DIALOG_AUTH,
            new LoginDialogListener());

And see below link for more information.

Facebook Login Issue

Community
  • 1
  • 1
Dipak Keshariya
  • 22,193
  • 18
  • 76
  • 128