3

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 ?

Community
  • 1
  • 1
Abhinav Manchanda
  • 6,546
  • 3
  • 39
  • 46
  • It may be because as your application is restarted by calling the callback a new instance is created of your Activity. However, **facebookClient** is only instantiated in **onClick()**. – ldx Feb 09 '11 at 13:03
  • If that was the case, wouldn't this issue happen every time I try to publish something on to Facebook ? However, this issue occurs less than 1% of the time. – Abhinav Manchanda Feb 09 '11 at 13:15
  • Were you ever able to resolve this? I'm having the same issue: Works on my phone/emulator, but crashes on other phones (namely Moto Droids). – Nelson Monterroso Feb 27 '11 at 01:04
  • No I wasn't. I read somewhere that it was a problem with one particular build that came with the Droid. Now I explicitly mention in my app description that FB publishing might not work with a couple of phones including Droid, and I've also put in a try catch block which shows an error on the screen saying FB publishing failed. Please let me know if you get to the bottom of the issue ! – Abhinav Manchanda Feb 27 '11 at 13:43
  • Apparently this is a problem with Droid in general, not just Facebook. https://groups.google.com/group/android-developers/browse_thread/thread/92d6f063682d2ca4/2c56e6e85c51e507?lnk=raot&hl=en&pli=1 – Abhinav Manchanda Feb 28 '11 at 11:20

3 Answers3

2

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.

Raanan
  • 4,777
  • 27
  • 47
1

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.

CloudWalker
  • 313
  • 4
  • 12
  • Very interesting. I was never able to reproduce this problem on my own phone, however, let me try it out on my friend's phone when I next meet him and get back to you on how successful it turns out to be. Thanks for sharing it. – Abhinav Manchanda Oct 14 '11 at 19:10
0

I have the same problem, some users of my application reported a chrash and, maybe, finally, I've been able to reproduce the problem systematically. On Android 4 there is a parameter among the "developer options", "Don't keep activities". If you enable it, each time you make a login with your application through SSO you will have a crash. The problem happens inside Facebook.class on the line: mAuthDialogListener.onComplete(data.getExtras()); because mAuthDialogListener is null. This method to reporduce the problem is equivalent to the situation mentioned by Raanan.