title: How to use facebook login from a sub activity instead mainactivity
body: <p>I am kind of new to all these integrations of facebook and android SDKs. 
  I followed the beginners tutorials from facebook developers to perform a login and it worked,
  but when i combined it with my application it didn't work from the following reason:</p>
  
  <p>In my project i wrote a calling from the main activity to another Fragmentactivity (FBProfile) which is calling the login fragment.
  After facebook's authentication it is returned to OnResume in MainActivity instead the overided onActivityresult inside LoginFragment.</p>
  
  <p>I need to create this flow (if its possible): 
  MainActivity->FBProfile(FragmentActivity)->LoginFragment->Facebook->LoginFragment</p>
  
  <p><strong>The activity that is called by MainActivity:</strong></p>
  
  <pre><code>public class FBProfile extends FragmentActivity{
  
  
    private LoginFragment loginfragment; 
  
  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO Auto-generated method stub
        Log.i(" Facebook: ", "FBProfile-&gt;OnCreate");
        if(savedInstanceState==null)
        {
  loginfragment=new LoginFragment();
  getSupportFragmentManager().beginTransaction().add(android.R.id.content, loginfragment).commit();
  }
  else
  {
  loginfragment=(LoginFragment) getSupportFragmentManager().findFragmentById(android.R.id.content);
  }
  }  
  }
  </code></pre>
  
  <p><strong>The LoginFragment which is called from FBProfile:</strong></p>
  
  <pre><code>public class LoginFragment extends Fragment {
   private View login_view;
   private boolean isResumed = false;   
   private static final String TAG="LoginFragment";
   private UiLifecycleHelper uihelper;
   private LoginButton authbutton;
   private TextView userInfoTextView;
   private Session.StatusCallback callback=new Session.StatusCallback() {
  
          @Override
          public void call(Session session, SessionState state, Exception exception) {
              // TODO Auto-generated method stub
              onSessionStatechange(session, state, exception);
          }
      };
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          Log.i(" Facebook: ", "FBProfile-&gt;OnCreate-&gt;LoginFragment");
          login_view=inflater.inflate(R.layout.profilepage, container,false);
         userInfoTextView = (TextView) login_view.findViewById(R.id.userInfoTextView);
  
          authbutton=(LoginButton) login_view.findViewById(R.id.login_button);
          authbutton.setFragment(this);
          authbutton.setReadPermissions(Arrays.asList("public_profile","email","user_birthday"));
  
          return login_view;
      }
  
      @SuppressWarnings("deprecation")
      private void onSessionStatechange(Session session,SessionState state,Exception exception)
      {
          if (isResumed) {
              if (session != null &amp;&amp; session.isOpened()) {
                  Intent intent = new Intent(getActivity(),
                          FBProfile.class);
                  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                          | Intent.FLAG_ACTIVITY_NEW_TASK);
                  startActivity(intent);
              }
          }
          if(state.isOpened()){
              Log.i(" Facebook: ", "LOGGED IN....");
              userInfoTextView.setVisibility(View.VISIBLE);
  
               // Request user data and show the results
              Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
  
                  @Override
                  public void onCompleted(GraphUser user, Response response) {
                      // TODO Auto-generated method stub
                      if (user != null) {
                          // Display the parsed user info
                          userInfoTextView.setText(buildUserInfoDisplay(user));
                      }
                  }
              });
  
  
              Toast.makeText(getActivity(), "Logged In", Toast.LENGTH_LONG).show();
          }
          else
          {
               userInfoTextView.setVisibility(View.INVISIBLE);
              if (Session.getActiveSession() != null) {
                  Session.getActiveSession().closeAndClearTokenInformation();
              }
  
              Session.setActiveSession(null);
              Toast.makeText(getActivity(), "Logged Out", Toast.LENGTH_LONG).show();
              Log.i(" Facebook: ", "LOGGED OUT....");
          }
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          uihelper=new UiLifecycleHelper(getActivity(), callback);
          uihelper.onCreate(savedInstanceState);
      }
  
      @Override
      public void onResume() {
          // TODO Auto-generated method stub
          super.onResume();
          Session session=Session.getActiveSession();
          if((session!=null)&amp;&amp;(session.isOpened()||session.isClosed()))
          {
              onSessionStatechange(session, session.getState(), null);
  
          }
          isResumed = true;
          uihelper.onResume();
      }
  
      @Override
      public void onPause() {
          // TODO Auto-generated method stub
          super.onPause();
          uihelper.onPause();
      }
      @Override
      public void onSaveInstanceState(Bundle outState) {
          // TODO Auto-generated method stub
          super.onSaveInstanceState(outState);
          uihelper.onSaveInstanceState(outState);
      }
      @Override
      public void onDestroy() {
          // TODO Auto-generated method stub
          super.onDestroy();
          uihelper.onDestroy();
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          Log.i("LoginFragment: ","onActivityResult Called");
          Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data);
      }
      /**
       * 
       * @param user
       * @return
       */
      private String buildUserInfoDisplay(GraphUser user) {
          StringBuilder userInfo = new StringBuilder("");
  
          // Example: typed access (name)
          // - no special permissions required
          userInfo.append(String.format("Name: %s\n\n", 
              user.getName()));
  
          // Example: typed access (birthday)
          // - requires user_birthday permission
          userInfo.append(String.format("Birthday: %s\n\n", 
              user.getBirthday()));
  
          // Example: partially typed access, to location field,
          // name key (location)
          // - requires user_location permission
    //      userInfo.append(String.format("Location: %s\n\n", 
    //          user.getLocation().getProperty("name")));
  
          // Example: access via property name (locale)
          // - no special permissions required
  //        userInfo.append(String.format("Locale: %s\n\n", 
   //           user.getProperty("locale")));
  
          // Example: access via key for array (languages) 
          // - requires user_likes permission
          JSONArray languages = (JSONArray)user.getProperty("languages");
          if (languages.length() &gt; 0) {
              ArrayList&lt;String&gt; languageNames = new ArrayList&lt;String&gt; ();
              for (int i=0; i &lt; languages.length(); i++) {
                  JSONObject language = languages.optJSONObject(i);
                  // Add the language name to a list. Use JSON
                  // methods to get access to the name field. 
                  languageNames.add(language.optString("name"));
              }           
              userInfo.append(String.format("Languages: %s\n\n", 
              languageNames.toString()));
          }
  
          return userInfo.toString();
      }
  }
  </code></pre>
  
  <p>Part of my manifest settings: </p>
  
  <pre><code>&lt;uses-sdk android:minSdkVersion="14"
  android:targetSdkVersion="20" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
  &lt;uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt; 
  &lt;uses-permission android:name="android.permission.GET_TASKS"/&gt;
  &lt;application
  android:allowBackup="true"
  android:icon="@drawable/ic_launcher"
  android:label="@string/app_name"
  android:theme="@android:style/Theme.NoTitleBar" &gt;
  &lt;meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/APP_FB_ID"/&gt;
      &lt;activity
          android:name=".Splash"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
               &lt;action android:name="android.intent.action.CREATE_SHORTCUT" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".MainActivity"
          android:noHistory="false"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.DEAFULT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  </code></pre>