我正在按照教程登录Facebook http://www.androidhive.info/2012/03/android-facebook-connect-tutorial/。我已成功登录facebook。但是现在我在按下facebook对话框中的十字按钮时没有调用我的onCancel()方法。
这是我的代码。
public void loginToFacebook() {
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
facebook.setAccessToken(access_token);
}
if (expires != 0) {
facebook.setAccessExpires(expires);
}
if (!facebook.isSessionValid()) {
facebook.authorize(this,
new String[] { "email", "publish_stream" },
new DialogListener() {
@Override
public void onCancel() {
// Function to handle cancel event
Toast.makeText(context, "Canceld",
Toast.LENGTH_SHORT).show();
}
@Override
public void onComplete(Bundle values) {
// Function to handle complete event
// Edit Preferences and update facebook acess_token
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token",
facebook.getAccessToken());
editor.putLong("access_expires",
facebook.getAccessExpires());
editor.commit();
Log.i("onComplete", "Log");
}
@Override
public void onError(DialogError error) {
// Function to handle error
Log.i("onError", "Log");
}
@Override
public void onFacebookError(FacebookError fberror) {
// Function to handle Facebook errors
Log.i("FB Error", "Log");
}
});
}
我测试过它没有在onCancel()方法中显示我的吐司。
答案 0 :(得分:0)
尝试onDismiss(DialogInterface对话框){},通常,当作业完成并从屏幕上删除时,对话框将被取消。当用户想要转义对话框并按下后退按钮
时,将取消对话框