0

需要帮助 - 我有一些这样的注销代码

public void logoutFromFacebook() {
    mAsyncRunner.logout(this, new RequestListener() {

        public void onComplete(String response, Object state) {
            Log.d("Logout from Facebook", response);
            if (Boolean.parseBoolean(response) == true) {
                runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    // Login button visible
                    btnFbLogin.setVisibility(View.VISIBLE);
                    // making all remaining buttons invisible
                    btnFbGetProfile.setVisibility(View.INVISIBLE);
                    btnPostToWall.setVisibility(View.INVISIBLE);
                    btnShowAccessTokens.setVisibility(View.INVISIBLE);
                    btnFbLogout.setVisibility(View.INVISIBLE);
                }
            });
        }
    }
}

但是那个代码不起作用,当我点击注销时,再次点击登录,我没有再次输入用户名和密码,我想如果我点击注销,当我再次点击登录时,我可以再次输入用户名和密码,请需要解决方案,谢谢

4

1 回答 1

1

当用户按下注销按钮时,您必须像这样使用,您必须执行此代码

  public void runTestLogout() {
    if (testLogout()) {
        logoutText.setText("Logout Tests Passed");
    } else {
        logoutText.setText("Logout Tests Failed");
    }
}



 public boolean testLogout() {
    try {
        Log.d("Tests", "Testing logout");
        String response = authenticatedFacebook.logout(this);
        Log.d("Tests", "Got logout response: *" + response + "*");
        if (!response.equals("true")) {
            return false;
        }

        Log.d("Tests", "Testing logout on logged out facebook session");
        try {
            Util.parseJson(authenticatedFacebook.logout(this));
            return false;
        } catch (FacebookError e) {
            if (e.getErrorCode() != 101 || 
                    !e.getMessage().equals("Invalid API key") ) {
                return false;
            }
        }

        Log.d("Tests", "Testing logout on unauthenticated object");
        try {
            Util.parseJson(new Facebook(APP_ID).logout(this));
            return false;
        } catch (FacebookError e) {
            if (e.getErrorCode() != 101 || 
                    !e.getMessage().equals("Invalid API key") ) {
                return false;
            }
        }

        Log.d("Tests", "All Logout Tests Passed");
        return true;
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
}

主要的是

  String response = authenticatedFacebook.logout(this);

通过运行此代码,您现在将注销,您可以再次登录,您将获得空的用户名和密码按钮

于 2012-09-13T04:22:17.670 回答