title: Android google+ login in a fragment
body: <p>Currently I am trying to implement google+ login using fragment so I can use it from different activities. I have created fragment like this</p>
  
  <pre><code>public class GoogleSignUpFragment extends Fragment implements
      ConnectionCallbacks, OnConnectionFailedListener, OnClickListener {
  
  // PlusClient Variables
  private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
  private ProgressDialog mConnectionProgressDialog;
  private PlusClient mPlusClient;
  private ConnectionResult mConnectionResult;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
  
      mPlusClient = new PlusClient.Builder(getActivity()
              .getApplicationContext(), this, this)
              .setActions("http://schemas.google.com/AddActivity",
                      "http://schemas.google.com/BuyActivity")
              .setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_PROFILE).build();
  
      getActivity().findViewById(R.id.sign_in_button)
              .setOnClickListener(this);
  
      // Progress bar to be displayed if the connection failure is not
      // resolved.
      mConnectionProgressDialog = new ProgressDialog(getActivity());
      mConnectionProgressDialog.setMessage("Signing in...");
  
  }
  
  @Override
  public void onStart() {
      // TODO Auto-generated method stub
      super.onStart();
      mPlusClient.connect();
  }
  
  @Override
  public void onStop() {
      // TODO Auto-generated method stub
      super.onStop();
      mPlusClient.disconnect();
  }
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent intent) {
      if (requestCode == REQUEST_CODE_RESOLVE_ERR
              &amp;&amp; resultCode == Activity.RESULT_OK) {
          mConnectionResult = null;
          mPlusClient.connect();
      }
  }
  
  @Override
  public void onClick(View view) {
      if (view.getId() == R.id.sign_in_button &amp;&amp; !mPlusClient.isConnected()) {
          if (mConnectionResult == null) {
              mConnectionProgressDialog.show();
  
          } else {
              try {
                  mConnectionResult.startResolutionForResult(getActivity(),
                          REQUEST_CODE_RESOLVE_ERR);
              } catch (SendIntentException e) {
                  // Try connecting again.
                  mConnectionResult = null;
                  mPlusClient.connect();
              }
          }
      }
  }
  
  @Override
  public void onConnectionFailed(ConnectionResult result) {
      if (mConnectionProgressDialog.isShowing()) {
          // The user clicked the sign-in button already. Start to resolve
          // connection errors. Wait until onConnected() to dismiss the
          // connection dialog.
          if (result.hasResolution()) {
              try {
                  result.startResolutionForResult(getActivity(),
                          REQUEST_CODE_RESOLVE_ERR);
              } catch (SendIntentException e) {
                  mPlusClient.connect();
              }
          }
      }
  
  }
  
  @Override
  public void onConnected(Bundle connectionHint) {
      mConnectionProgressDialog.dismiss();
      Toast.makeText(getActivity().getApplicationContext(),
              "User is connected!", Toast.LENGTH_LONG).show();
      Intent intent = new Intent(getActivity().getApplicationContext(),
              LogoutActivity.class);
      startActivity(intent);
  
  }
  
  @Override
  public void onDisconnected() {
      // TODO Auto-generated method stub
  
  }
  
  }
  </code></pre>
  
  <p>I was doing it with the official tutorial, and then reworking a little to use it inside fragment.</p>
  
  <p>In main activity I have:</p>
  
  <pre><code>FragmentManager fragmentManager = getSupportFragmentManager();
      android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
  
      googleSignUpFragment = new GoogleSignUpFragment();
      fragmentTransaction.add(R.id.detailFragment, googleSignUpFragment);
      fragmentTransaction.commit();
  </code></pre>
  
  <p>However whenever I click the log-in button, there is only dialog that says "Signing in..." and nothing else happens. Any ideas how to fix that problem? It was working just fine inside normal activity.</p>
  
  <p>Thanks for any help.</p>
  
  <p>@Edit.
  I have figured out that the onConnectionFailed method is not launched, and so there is no onActivityResult it seems, however when I put directly mPlusClient.connect() inside my click it works, but I feel like its not a proper way to do that. Maybe the problem is about that onConnectionFailed not beign launched</p>
  
  <p>@Edit 2.
  Now I have figured out that the problem seems to be with dialog.isShowing() as, when I remove the line, account chooser is showing, right after start, tried with bool value, that I change after click however this does not work too...</p>