Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8436215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:07:19+00:00 2026-06-10T07:07:19+00:00

I am trying to integrate Facebook login with my app. It’s simple: a user

  • 0

I am trying to integrate Facebook login with my app. It’s simple: a user clicks a button on my Login screen, I get their email and other info from Facebook, then I submit that information to my website and make them an account (I don’t use passwords, so this works).

However, the login button only works like 1/3 of the time. Other times it launches the Facebook activity, I see a loading spinner on the Facebook screen, and then the app exits to my home screen. No force close notification, no logcat errors, just nothing.

Here is the code for my login activity (the parts relevant to Facebook):

package com.taptag.beta;

/** IMPORTS REMOVED FOR BREVITY **/

public class FacebookLogInActivity extends NetworkActivity {
    public static final String APP_ID = "OMITTED FOR PRIVACY";
    public static final String LOG_OUT = "Log Out";

    Facebook facebook = new Facebook(APP_ID);

    private AsyncFacebookRunner mAsyncRunner;
    private Handler mHandler;
    private SharedPreferences mPrefs;
    private Button mLoginButton;
    private static final String[] PERMISSIONS = { "email" };

    private EditText firstName;
    private EditText lastName;
    private EditText email;
    private Button signupButton;

    private TextView errorView;
    private ProgressBar facebookSpinner;
    private ProgressBar signupSpinner;

    //Taken from mkyong
    private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
    private Pattern emailPattern;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.facebook_main);

        mPrefs = getSharedPreferences("TapTag", MODE_PRIVATE);
        Integer userId = mPrefs.getInt("user_id", -1);

        mLoginButton = (Button) findViewById(R.id.loginButton);

        // Facebook properties
        mAsyncRunner = new AsyncFacebookRunner(facebook);
        mHandler = new Handler();
        // Get existing saved session information
        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);
        }

        errorView = (TextView) findViewById(R.id.signupError);
        facebookSpinner = (ProgressBar) findViewById(R.id.facebookSpinner);
        signupSpinner = (ProgressBar) findViewById(R.id.signupSpinner);

        hideSpinners();
        errorView.setVisibility(View.GONE);

        emailPattern = Pattern.compile(EMAIL_PATTERN);
        firstName = (EditText) findViewById(R.id.signupFirstName);
        lastName = (EditText) findViewById(R.id.signupLastName);
        email = (EditText) findViewById(R.id.signupEmail);
        signupButton = (Button) findViewById(R.id.signupButton);

        signupButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isValid = validateInputs();
                if (isValid) {
                    SignupTask signupTask = new SignupTask();
                    signupTask.execute(null, null);
                }
            }
        });

        mLoginButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!facebook.isSessionValid()) {
                    logIn();
                } else {
                    logOut();
                }
            }
        });
    }

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

    @Override
    public void onResume() {
        super.onResume();
        // Extend the session information if it is needed
        //if (facebook != null && !facebook.isSessionValid()) {
            facebook.extendAccessTokenIfNeeded(this, null);
        //}
        if (LOG_OUT.equals(getIntent().getAction())) {
            logOut();
        } else  {
            Integer userId = mPrefs.getInt("user_id", -1);
            if (userId > 0) {
                continueToHomeScreen();
            }
        }
    }

    @Override
    public void onBackPressed() {
        //Do nothing, don't want people getting back into the app
    }

    /**
     * Validate the signup form.  True if valid, false otherwise.
     * @return
     */
    public boolean validateInputs() {
        /** NOT RELEVANT **/
    }

    private FacebookUserInfo userFromForm() {
        /** NOT RELEVANT **/
    }

    private boolean validateFirstName() {
        /** NOT RELEVANT **/
    }

    private boolean validateLastName() {
        /** NOT RELEVANT **/
    }

    private boolean validateEmail() {
        /** NOT RELEVANT **/
    }

    public void hideSpinners() {
        facebookSpinner.setVisibility(View.GONE);
        signupSpinner.setVisibility(View.GONE);
    }

    public void continueToHomeScreen() {
        Intent toHomeScreen = new Intent(FacebookLogInActivity.this, HomeScreenActivity.class);
        FacebookLogInActivity.this.startActivity(toHomeScreen);
    }

    public void logIn() {
        facebookSpinner.setVisibility(View.VISIBLE);
        mLoginButton.setVisibility(View.GONE);
        facebook.authorize(FacebookLogInActivity.this, PERMISSIONS, 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();
                requestUserData();
            }

            @Override
            public void onFacebookError(FacebookError e) {
                mLoginButton.setVisibility(View.VISIBLE);
                hideSpinners();

            }
            @Override
            public void onError(DialogError e) {
                mLoginButton.setVisibility(View.VISIBLE);
                hideSpinners();
            }
            @Override
            public void onCancel() {
                mLoginButton.setVisibility(View.VISIBLE);
                hideSpinners();
            }
        });
    }

    public void logOut() {
        /** NOT RELEVANT **/
    }

    public void requestUserData() {
        Bundle params = new Bundle();
        params.putString("field name", "name");
        params.putString("field email", "email");

        mAsyncRunner.request("me", params, new BaseRequestListener() {
            @Override
            public void onComplete(final String response, final Object state) {
                FacebookUserInfo facebookUserInfo = TapTagAPI.userInfoFromFacebook(response);
                UserFetchResponse userFetchResponse = TapTagAPI.fetchUser(facebookUserInfo);
                if (!userFetchResponse.hasError()) {
                    commitUserInfo(userFetchResponse);
                    continueToHomeScreen();
                } else {
                    mHandler.post(new Runnable() {
                        @Override
                        public void run() {
                            hideSpinners();
                            mLoginButton.setVisibility(View.VISIBLE);
                        }
                    });
                }
            }
        });
    }

    public void commitUserInfo(UserFetchResponse userFetchResponse) {
        SharedPreferences.Editor editor = mPrefs.edit();
        editor.putInt("user_id", userFetchResponse.getId());
        editor.putString("user_name", userFetchResponse.getFirst() + " " + userFetchResponse.getLast());
        editor.commit();
    }

    public class SignupTask extends AsyncTask<Void, Void, UserFetchResponse> {
        @Override
        protected void onPreExecute() {
            signupSpinner.setVisibility(View.VISIBLE);
            signupButton.setVisibility(View.GONE);
        }

        @Override
        protected UserFetchResponse doInBackground(Void... arg0) {
            FacebookUserInfo user = userFromForm();
            UserFetchResponse response = TapTagAPI.fetchUser(user);
            return response;
        }

        @Override
        protected void onPostExecute(UserFetchResponse response) {
            if (response.success()) {
                commitUserInfo(response);
                continueToHomeScreen();
            } else {
                errorView.setVisibility(View.VISIBLE);
            }
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:07:21+00:00Added an answer on June 10, 2026 at 7:07 am

    Write below login function instead of your login function, it will solve your problem.

    public void logIn() {
        facebookSpinner.setVisibility(View.VISIBLE);
        mLoginButton.setVisibility(View.GONE);
        facebook.authorize(FacebookLogInActivity.this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, 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();
                requestUserData();
            }
    
            @Override
            public void onFacebookError(FacebookError e) {
                mLoginButton.setVisibility(View.VISIBLE);
                hideSpinners();
            }
    
            @Override
            public void onError(DialogError e) {
                mLoginButton.setVisibility(View.VISIBLE);
                hideSpinners();
            }
    
            @Override
            public void onCancel() {
                mLoginButton.setVisibility(View.VISIBLE);
                hideSpinners();
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to integrate a Facebook send button into my site using Facebook app.
I'm trying to integrate both the Facebook login button and the comments plugin on
I'm trying to integrate facebook login on my android app. I found a lot
I have been trying to integrate Facebook with my app to allow users to
I am trying to integrate Facebook to my Android app for social post. I
So I am trying to integrate the facebook iOS api into my iphone app.
I'm trying to integrate facebook login on a site I'm working on, but so
I'm trying to integrate Facebook into my Android Java app, what I want it
I am trying to integrate facebook capabilities into my Android app. So, I have
I am trying to integrate Facebook into my webpage so users can update their

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.