2016-12-02 14 views
0

如何将用户开放应用,而无需签到始终,当用户不退出..我已经使用sharedpreff但登录机器人 - 登录到Google,总是要求

这个代码仍然请求登录

private void handleSignInResult(GoogleSignInResult result) { 
     Log.d("Hasil", "handleSignInResult:" + result.isSuccess()); 
     Log.d("Hasil", "handleSignInResult:" + result.toString()); 
     if (result.isSuccess()) { 
      // Signed in successfully, show authenticated UI. 
      GoogleSignInAccount acct = result.getSignInAccount(); 
      String nama = acct.getDisplayName(); 
      String email = acct.getEmail(); 
      String id = acct.getId(); 
      String foto = String.valueOf(acct.getPhotoUrl()); 

      session.createLoginSession(id,nama,email,foto); 
      SharedPrefApp sharedPref; 
      sharedPref = SharedPrefApp.getInstance(); 

      sharedPref.saveISLogged_IN(this, true);//add this on user sucessful login 

      Intent i = new Intent(getApplicationContext(),WelcomeActivity.class); 
      startActivity(i); 
      finish(); 
     } else { 
      Snackbar.make(((ViewGroup) findViewById(android.R.id.content)).getChildAt(0), "GAGAL LOGIN", Snackbar.LENGTH_SHORT).show(); 
     } 
    } 

回答

0

为我工作!

mGoogleApiClient.clearDefaultAccountAndReconnect(); 
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
startActivityForResult(signInIntent, RC_SIGN_IN); 

确保mGoogleApiClient不为空