How do I hide the login button after that I have logged in to Facebook in my app? I want to put my login(logout) button in menu_login.xml or another place.
my 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
<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);
- I cant put the login/out button in the new Activity.
- 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.
So, how do I hide the logout button after login in?
Thanks.