title: Saving user credentials from google sign in with Android?
body: <p>Okey. I integrated a google sign in feature in my android app. 
  This is my login activity</p>
  
  <pre><code>public class LoginActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener {
  
  //button
  private SignInButton signInButton;
  //options
  private GoogleSignInOptions gso;
  //client api
  private GoogleApiClient mGoogleApiClient;
  
  private static  final int LCD = 4;
  
  
  
  
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_google_login);
  
  
      gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
              .requestEmail()
              .build();
      mGoogleApiClient = new GoogleApiClient.Builder(this)
              .enableAutoManage(this,this)
              .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
              .build();
  
      signInButton = (SignInButton) findViewById(R.id.sign_in_button);
      signInButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
             Intent intent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
              startActivityForResult(intent,LCD);
  
          }
      });
  
  
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if(requestCode == LCD){
  
          GoogleSignInResult result =  Auth.GoogleSignInApi.getSignInResultFromIntent(data);
          handleSignInResult(result);
  
  
      }
  }
  
  private void handleSignInResult(GoogleSignInResult result) {
      //check if the operation  is successful
      if(result.isSuccess()){
  
          goMainScreen();
  
  
  
      }else {
          Toast.makeText(this,"Something went wrong",Toast.LENGTH_SHORT).show();
      }
  
  
  
  
  }
  
  private void goMainScreen() {
  
      Intent secondActivity = new Intent(this, ProfileActivity.class);
      secondActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
              | Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivity(secondActivity);
  
  }
  
  @Override
  public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Once, login is successful, i open Profile activity, and get the user image and the name
  ProfileActivity</p>
  
  <pre><code>public class ProfileActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener {
  
  
  private ImageView photo;
  private TextView name;
  
  private GoogleApiClient googleApiClient;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_profile);
      photo = (ImageView) findViewById(R.id.profileImage);
      name = (TextView) findViewById(R.id.theName);
  
      GoogleSignInOptions gsp = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
              .requestEmail()
              .build();
  
      googleApiClient = new GoogleApiClient.Builder(this)
              .enableAutoManage(this,this)
              .addApi(Auth.GOOGLE_SIGN_IN_API, gsp)
              .build();
  
  }
  
  
  @Override
  protected void onStart() {
      super.onStart();
  
  
      OptionalPendingResult&lt;GoogleSignInResult&gt; optionalPendingResult = Auth.GoogleSignInApi.silentSignIn(googleApiClient);
  
      if(optionalPendingResult.isDone()){
  
          GoogleSignInResult sig = optionalPendingResult.get();
          handleSigninResult(sig);
  
  
      }else {
          optionalPendingResult.setResultCallback(new ResultCallback&lt;GoogleSignInResult&gt;() {
              @Override
              public void onResult(@NonNull GoogleSignInResult googleSignInResult) {
                  handleSigninResult(googleSignInResult);
              }
          });
  
      }
  
  }
  
  private void handleSigninResult(GoogleSignInResult sig) {
      if(sig.isSuccess()){
  
          GoogleSignInAccount acc =  sig.getSignInAccount();
          //accessing  the data
          name.setText(acc.getDisplayName());
  
          //image with glide
          Glide.with(this).load(acc.getPhotoUrl()).into(photo);
  
      }else {
          //in case is not successful
          //send the user to the Login Screen
          goLoginInScree();
  
      }
  
  
  }
  
  private void goLoginInScree() {
      Intent goUser = new Intent(this, LoginActivity.class);
      goUser.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivity(goUser);
  
  
  }
  
  @Override
  public void onConnectionFailed( ConnectionResult connectionResult) {
  
  }
  </code></pre>
  
  <p>My next issue is, how do i implement feature for automatically login in, if the user is already been logged to the activity? I don't want every time app is open, to click Sign in button, but directly to go to profile activity. </p>