简体   繁体   English

Facebook SDK 4.4。+ | 登录后如何隐藏注销按钮?

[英]Facebook SDK 4.4.+ | How do I hide logout button after login?

How do I hide the login button after that I have logged in to Facebook in my app? 在应用程序中登录Facebook后,如何隐藏登录按钮? I want to put my login(logout) button in menu_login.xml or another place. 我要将我的登录(注销)按钮放在menu_login.xml或其他位置。

my LoginActivity. 我的LoginActivity。

public class LoginActivity extends AppCompatActivity {

private LoginButton loginButton;
private CallbackManager callbackManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();

    setContentView(R.layout.activity_login);

    loginButton = (LoginButton) findViewById(R.id.login_button);

    // Callback registration
    loginButton.registerCallback(callbackManager, new     FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Intent intent = new Intent (LoginActivity.this,     MainActivity.class);
            startActivity(intent);


        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException exception) {

        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent         data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}
}

This is what I put in the menu_login.xml 这就是我在menu_login.xml中输入的内容

    <item android:id="@+id/login_button" android:title="Log out"
    android:orderInCategory="10" app:showAsAction="never" />

But when I press the log out button, nothing will happen. 但是,当我按下注销按钮时,什么也不会发生。

I have also tried this to send me from one to another Activity after the login, but then more problems comes up. 登录后,我也尝试过使用此操作将我从一个活动发送到另一个活动,但是随后出现了更多问题。

 @Override
        public void onSuccess(LoginResult loginResult) {
            Intent intent = new Intent (LoginActivity.this, MainActivity.class);
            startActivity(intent);
  1. I cant put the login/out button in the new Activity. 我无法在新的活动中添加“登录/退出”按钮。
  2. When I press the login, it will jump fast to the logout button site and then to the new Activity, and thats weird, so I dont want to send from one to another Activity. 当我按下登录名时,它将快速跳转到注销按钮站点,然后跳转到新的Activity,那很奇怪,所以我不想从一个发送到另一个Activity。

So, how do I hide the logout button after login in? 那么,登录后如何隐藏注销按钮?

Thanks. 谢谢。

You could use the local broadcast manager class and broadcast in your application that you have successfully logged into Facebook. 您可以使用本地广播管理器类,并在您已成功登录Facebook的应用程序中广播。 Your MainActivity (or whoever is interested) would then need to listen to that broadcast and act accordingly. 然后,您的MainActivity(或感兴趣的任何人)将需要收听该广播并采取相应的措施。

More info: http://developer.android.com/intl/es/reference/android/support/v4/content/LocalBroadcastManager.html 更多信息: http : //developer.android.com/intl/es/reference/android/support/v4/content/LocalBroadcastManager.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM