Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crashes after first Facebook Login

Sometimes (not very frequently) my android app crashes after first logging to facebook using Facebook Login (Facebook SDK version 3.5).

I'm getting exception:

java.lang.RuntimeException: Unable to resume activity {my.app.package/com.facebook.LoginActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=0, data=null} to activity {my.app.package/com.facebook.LoginActivity}: java.lang.NullPointerException

with 2 different root exceptions:

Sometimes with:

java.lang.NullPointerException at com.facebook.AuthorizationClient.startOrContinueAuth(AuthorizationClient.java:135)

And sometimes:

Caused by: java.lang.NullPointerException at com.facebook.AuthorizationClient.logAuthorizationMethodComplete(AuthorizationClient.java:519)

In most cases my app is working fine.

Any ideas what may cause this problem?

EDIT:

My facebook sdk conf in manifest:

<activity
        android:name="com.facebook.LoginActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/applicationId" />

Activity code:

public class MainActivity extends FragmentActivity {

....

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

    initSession(savedInstanceState);
    ...
}



private void initSession(Bundle savedInstanceState) {

    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

    Session session = Session.getActiveSession();
    if (session == null) {
        if (savedInstanceState != null) {
            session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
        }
        if (session == null) {
            session = new Session(this);
        }
        Session.setActiveSession(session);
        if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
        }
    }

}


@Override
public void onStart() {
    super.onStart();
    Session session = Session.getActiveSession();
    if (session != null) {
        session.addCallback(statusCallback);
    }

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Session session = Session.getActiveSession();
    if (session != null) {
        session.onActivityResult(this, requestCode, resultCode, data);
    }

}

@Override
public void onStop() {
    super.onStop();


    Session session = Session.getActiveSession();
    if (session != null) {
        session.removeCallback(statusCallback);
    }

}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Session session = Session.getActiveSession();
    Session.saveSession(session, outState);
}

...

}

I also got this error with previous version of Facebook SDK. I have latest Fb android client. Any help?

like image 913
Michal W Avatar asked Sep 11 '13 23:09

Michal W


People also ask

Why is my Facebook app closing as soon as I open it?

Apps closing as soon as they're open is often caused by a lack of free space on the device or a weak internet connection. Try the solutions at the top of this page to find the cause and stop apps from shutting down after they're opened.

Why are my apps crashing as soon as I open them?

This usually occurs when your Wi-Fi or cellular data is slow or unstable, causing apps to malfunction. Another reason for Android apps crashing can be a lack of storage space in your device. This can occur when you overload your device's internal memory with heavy apps.

Why does a certain app keep crashing?

This usually occurs when your Wi-Fi or cellular data is slow or unstable, and apps tend to malfunction. Another reason for Android apps crashing problem is the lack of storage space in your device. This occurs when you overload your device's internal memory with heavy apps as well.


1 Answers

Facebook just released v3.5.1 of their Android SDK yesterday that addresses your issues. Their Change Log doesn't give much information about what went wrong, but people have been reporting this bug and they did say it would be fixed in a later version (source). But anyway, looking at the diffs between v3.5 and v3.5.1 they seem to have fixed code around lines 135 and 519. Check out the Change Log the complete list. Probably a good idea never to upgrade to a significant version from Facebook until they release their first patch to it.

like image 145
rarp Avatar answered Sep 29 '22 03:09

rarp