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?
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.