我已经关注了谷歌开发者网站https://developers.google.com/+/quickstart/android的快速启动示例应用程序,它在同一活动中的登录按钮,注销和撤销按钮上运行良好。
但是当我尝试将注销按钮移动到新活动并调用注销按钮时,它开始崩溃。
这就是我想要做的事情:
@Override
public void onConnected(Bundle connectionHint) {
// Reaching onConnected means we consider the user signed in.
Log.i(TAG, "onConnected");
// Update the user interface to reflect that the user is signed in.
// Retrieve some profile information to personalize our app for the user.
Person currentUser = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);
mStatus.setText(String.format(
getResources().getString(R.string.signed_in_as),
currentUser.getDisplayName()));
Intent myIntent = new Intent(LoginActivity.this, LogOutActivityty.class);
//myIntent.putExtra("GUsername", currentUser.getDisplayName());
startActivity(myIntent);
// Indicate that the sign in process is complete.
mSignInProgress = STATE_DEFAULT;
}
这是我的LogOut活动:
Logout = (Button) findViewById(R.id.sign_out_button);
Logout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (mGoogleApiClient.isConnected()) {
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
mGoogleApiClient.disconnect();
mGoogleApiClient.connect();
Intent i = new Intent(LogOutActivity.this, LoginActivity.class);
startActivity(i);
Toast.makeText(getApplicationContext(), "Logged out using Google Account", Toast.LENGTH_LONG).show();
}
}
});