Android Fragment Support for the Facebook SDK

Recently, I have been working with the Android Facebook SDK and had a problem calling authorize from a Fragment. I discovered that my Fragment was not getting the resulting onActivityResult callback. After looking through the Facebook SDK code, I discovered that startActivityResult was being called on the instance of the Activity passed into the authorize call. As a result, the onActivityResult was getting called back on the Activity, not my Fragment.

I forked the official Android Facebook sdk hosted at Github and added Fragment support myself. The change is pretty simple, basically added a new authorize function that passes a Fragment. Now my Fragment gets the onActivityResult callback. Hurray!

Paul Soucy

Read more posts by this author.