从片段中注销 google 帐户(底部导航)
Signing out google account from fragement(bottomnavigation)
由于注销按钮在 fragment 上,我不能将“this”用作 Activity,有什么可以替换的吗?
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this,gso);
错误信息
error: no suitable method found for getClient(DashboardFragment,GoogleSignInOptions)
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this,gso);
^
method GoogleSignIn.getClient(Context,GoogleSignInOptions) is not applicable
(argument mismatch; DashboardFragment cannot be converted to Context)
method GoogleSignIn.getClient(Activity,GoogleSignInOptions) is not applicable
(argument mismatch; DashboardFragment cannot be converted to Activity)
GoogleSignIn.getClient(Context,GoogleSignInOptions)
需要上下文而不是片段。
这样使用:
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(getContext(),gso);
请注意,如果未附加片段,getContext()
可能 return null
。
由于注销按钮在 fragment 上,我不能将“this”用作 Activity,有什么可以替换的吗?
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this,gso);
错误信息
error: no suitable method found for getClient(DashboardFragment,GoogleSignInOptions)
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(this,gso);
^
method GoogleSignIn.getClient(Context,GoogleSignInOptions) is not applicable
(argument mismatch; DashboardFragment cannot be converted to Context)
method GoogleSignIn.getClient(Activity,GoogleSignInOptions) is not applicable
(argument mismatch; DashboardFragment cannot be converted to Activity)
GoogleSignIn.getClient(Context,GoogleSignInOptions)
需要上下文而不是片段。
这样使用:
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(getContext(),gso);
请注意,如果未附加片段,getContext()
可能 return null
。