我在我的 Android 应用中集成了 Google Sign-In。现在我想在另一个 Activity 中实现注销操作(注销按钮),相对于存在登录按钮的 Activity 。
正在关注google tutorial ,为了注销用户,我必须调用在登录阶段获得的 GoogleSignInClient
对象。
如何将此对象传递给 Intent 中的另一个 Activity ?这是应该遵循的正确程序,还是有其他方法可以实现这一目标?
这是我的代码:
FirstActivity.java
private GoogleSignInClient mGoogleSignInClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
// Set the dimensions of the sign-in button.
SignInButton signInButton = findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_STANDARD);
signInButton.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.sign_in_button:
Log.d(LOG_TAG, "Google button clicked!");
signIn();
break;
}
}
private void updateUI(@Nullable GoogleSignInAccount account) {
if(account != null){
Intent intent = new Intent(this, SecondActivity.class);
String email = account.getEmail();
intent.putExtra(Intent.EXTRA_EMAIL, email);
startActivity(intent);
}
}
最佳答案
无需传递对象,因为您可以使用 GoogleSignIn.getLastSignedInAccount
请求当前登录用户的个人资料信息的方法。
更多信息:
https://developers.google.com/identity/sign-in/android/people
关于android - 如何将 Google 登录对象传递给另一个 Android Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49135812/