Unable to exit other activity (Facebook - Android)




I am creating an application and I have successfully enabled Facebook login using the Facebook SDK 4.7.0. I use LoginManager (not LoginButton) since I want to have a custom button.
The stream is as follows:

  • Open the app and welcome MainActivity
  • Press the "START" button and open the "SignInActivity", where you click the "Log in using the Facebook button" button, it logs and closes this activity.
  • Then you are back on the MainActivity screen.
  • In the navigation box slider, I have a LOGOUT button at the bottom, I initialized it, and I only show it when you are logged in, that is, when the user_id of your Facebook profile is not null .

I implemented the following on the Logout onClickListener button:

FacebookSdk.sdkInitialize(getApplication().getApplicationContext()); LoginManager.getInstance().logOut();

But when I press the button on my device, it does nothing (it only shows ViewPostImeInputStage ACTION_DOWN in logcat, which is the standard for the button to be pressed.

I saw other posts on SO where this method worked, so I donโ€™t understand why it will not work in my case.

SignInActivity.java

  FacebookSdk.sdkInitialize(getApplication().getApplicationContext()); callbackManager = CallbackManager.Factory.create(); LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { Log.e(TAG, "User ID: " + loginResult.getAccessToken().getUserId()); Log.e(TAG, "Auth Token: " + loginResult.getAccessToken().getToken()); SharedPreferences prefs = getSharedPreferences("com.dotfreeride.dotfreeride.login", 0); SharedPreferences.Editor editor = prefs.edit(); editor.putString("userId", loginResult.getAccessToken().getUserId()); editor.putString("fbToken", loginResult.getAccessToken().getToken()); editor.commit(); } @Override public void onCancel() { Toast.makeText(SignInActivity.this, "Login attempt canceled!", Toast.LENGTH_SHORT).show(); } @Override public void onError(FacebookException error) { Toast.makeText(SignInActivity.this, "Login attempt failed!", Toast.LENGTH_SHORT).show(); } }); 

MainActivity.java

 logoutBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FacebookSdk.sdkInitialize(getApplication().getApplicationContext()); LoginManager.getInstance().logOut(); } }); 
+5
source share
1 answer

It worked for me

 public class Profile extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile); } public void gotoLogin(View view){ FacebookSdk.sdkInitialize(getApplicationContext()); LoginManager.getInstance().logOut(); Intent intent = new Intent(this, Login.class); startActivity(intent); } 

}

I had the same problem because I expanded AppCompatActivity. With ActionBar, this works. Hope this works for you :)

+1
source

Source: https://habr.com/ru/post/1236168/


All Articles