title: Does the Facebook SDK only work with Activities?
body: <p>I've been trying to implement the Facebook SDK into my application in order to let users post messages on our fanwall through the app. However, I've been unsuccessful at even logging the user in through the SDK.</p>
  
  <p>In the SDK examples, a simple sample has been given which uses an <code>Activity</code> to try and authorize the user using Single Sign-On. I've  tried this example myself, and it works. I'm able to log in, I had to authorize the app to use my Facebook data and I could see the requests being made and received in LogCat.</p>
  
  <p>Now, I've tried adding the same code to my own app. This app is <code>Fragment</code> based using the Compatibility package. There is one central <code>FragmentActivity</code> and the rest of my classes are simple <code>Fragments</code>. When adding the sample code to one of these <code>Fragments</code>, the Facebook app starts up for half a second when trying to authorize, but afterwards closes and nothing has happened. I'm back in my regular Fragment again.</p>
  
  <p>When checking the LogCat after this, nothing suggests that the Facebook app even opened or made any requests other than the fact it shows some printing checks I added and the fact it says it's starting the Facebook intent :</p>
  
  <pre><code>01-12 13:19:40.874: I/System.out(6087): Calling authorize
  01-12 13:19:40.874: I/ActivityManager(1380): Starting activity: Intent { cmp=com.facebook.katana/.ProxyAuth (has extras) } from pid 6087
  01-12 13:19:40.874: I/System.out(6087): Called authorize
  </code></pre>
  
  <p>Other than that, nothing gets returned. No Facebook-checks, no statements saying my keys are wrong or anything, just nothing. The Facebook intent was called, but closed almost immediately and nothing else shows that it was even open.</p>
  
  <p>This has been boggling my mind for a few hours now, and I'm starting to think the regular , sample-provided approach just doesn't work in <code>Fragments</code> due to the way <code>Fragments</code> work.</p>
  
  <p>The code I've been using is posted below. The Fragment gets fired by a button which calls a <code>FragmentTransaction</code>. Am I doing something fundamentally wrong here, or does the Facebook SDK really just not work with <code>Fragments</code>? I've tried searching for this problem but I haven't been able to find anyone else with the same sort of situation.</p>
  
  <hr>
  
  <pre><code>public class FanWallFacebook extends Fragment {
  
      Facebook facebook = new Facebook("294678133912628");
  
      public FanWallFacebook() {
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.filler, container, false);
      }
  
      @Override
      public void onStart() {
          super.onStart();
  
          System.out.println("Calling authorize");
          facebook.authorize(getActivity(), new DialogListener() {
              @Override
              public void onComplete(Bundle values) {
                  System.out.println("Completed");
              }
  
              @Override
              public void onFacebookError(FacebookError error) {
                  System.out.println("Facebook error: "+error.getMessage());
              }
  
  
              @Override
              public void onError(DialogError e) {
                  System.out.println("General error: "+e.getMessage());
              }
  
              @Override
              public void onCancel() {
                  System.out.println("Cancelled");
              }
          });
  
          System.out.println("Called authorize");
  
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
          facebook.authorizeCallback(requestCode, resultCode, data);
          System.out.println("Authorize callback'd");
      }
  
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>Just tried using a <code>FragmentActivity</code>, and lo and behold, that does work. It successfully logs in. Seems like the SDK really only works with classes that explicitly extend <code>...Activity</code>. Could anyone give me an idea why that might be the case? I always thought <code>Fragments</code> somewhere down the line extended <code>Activity</code> as well.</p>