Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Facebook SDK - Problem with authorizeCallback()

I have an Android application which, among other things, also publishes updates on Facebook.

I created my code according to this example and it works perfectly fine. The only difference in my code and the one in the link above is that I also extended onActivityResult as mentioned on the official Facebook SDK for Android page.

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

Sometimes however, I get a null pointer exception on the line where I call the "facebook.authorizeCallback()" within the onActivityResult() method.

This has never occurred on any of my mobile phones or emulators. However, I keep getting user crash reports, mostly from Droid and T-Mobile myTouch 3G phones. I tried a lot but was unable to reproduce the problem. Any body have any idea what could be wrong ?

like image 851
Abhinav Manchanda Avatar asked Mar 19 '26 22:03

Abhinav Manchanda


2 Answers

By looking in Facebook.java code it seems that the DialogListener and is kept as a private parameter in the class... when calling authorizeCallback() you assume that the DialogListener exits and isn't null. BUT if your phone is short on memory (like my G1 is) your calling activity is killed to vacate memory for the facebook login process those erasing your DialogListener when you call the autherizeCallback function you'll get a null pointer exception or the callback is ignored. This might be the cause of your problem.

like image 66
Raanan Avatar answered Mar 22 '26 13:03

Raanan


I had the same problem and solved it copying Facebook.DialogListener.onComplete(Bundle values) code inside a catch for facebookClient.authorizeCallback(requestCode, resultCode, data) NPE.

First I tried the code without calling authorizeCallback but session is not established yet then. authorizeCallback did everything that was needed and just failed to call listener. So, copying listener logic inside NPE catch seems to solve the problem.

like image 27
CloudWalker Avatar answered Mar 22 '26 11:03

CloudWalker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!