androidfacebookparse-platformparsefacebookutils

Android FacebookException : Login attempt failed


I am using ParseFacebookUtils to login to my app from Facebook.

LoginActivity's onCreate:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    loginButton = (Button)findViewById(R.id.loginButton);
    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {                  
            ParseFacebookUtils.logInWithReadPermissionsInBackground(LoginActivity.this,
                    Arrays.asList("public_profile", "email", "user_photos", "user_birthday"),
                    new LogInCallback() {
                        @Override
                        public void done(ParseUser user, ParseException e) {
                            if (user == null) {
                                Log.d(TAG, "Uh oh. The user cancelled the Facebook login.");
                            } else if (user.isNew()) {
                                Log.d(TAG, "User signed up and logged in through Facebook!");
                            } else {
                                Log.d(TAG, "User logged in through Facebook!");
                            }
                        }
                    }
            );
        }
    });
}

Application class onCreate:

public void onCreate() {
    super.onCreate();

    Parse.initialize(this, app_id, client_key);
    FacebookSdk.sdkInitialize(getApplicationContext());
    ParseFacebookUtils.initialize(getApplicationContext());
}

Crash error:

com.facebook.FacebookException: Log in attempt failed: LoginActivity could not be started
   at com.facebook.login.LoginManager.startLogin(LoginManager.java:382)
   at com.facebook.login.LoginManager.logInWithReadPermissions(LoginManager.java:262)
   at com.parse.FacebookAuthenticationProvider.authenticateAsync(FacebookAuthenticationProvider.java:150)
   at com.parse.ParseAuthenticationProvider.logInAsync(ParseAuthenticationProvider.java:57)
   at com.parse.ParseFacebookUtils.logInAsync(ParseFacebookUtils.java:259)
   at com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:155)
   at com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:167)
   at com.example.app.LoginActivity$1.onClick(LoginActivity.java:48)
   at android.view.View.performClick(View.java:4756)
   at android.view.View$PerformClick.run(View.java:19749)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5221)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

I keep getting the above crash when tapping on the login button.

Any ideas on how to fix this?

I have set the client id for Facebook and Parse in the strings.xml

UPDATE:

Facebook SDK v4.0.1

Custom button onClick()


Solution

  • Fixed it by adding the following in AndroidManifest.xml:

    <activity android:name="com.facebook.FacebookActivity"
              android:theme="@android:style/Theme.Translucent.NoTitleBar"
              android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
              android:label="@string/app_name" />
    

    According to this SO post, the above is needed in Facebook SDK 4.+.