简体   繁体   English

Android:Facebook注销功能

[英]Android: Facebook logout function

I am using the Facebook sdk 3.8, and I want to create a logout function. 我正在使用Facebook sdk 3.8,我想创建一个注销功能。 I have this button: 我有这个按钮:

<Button
   android:id="@+id/button_logout"
   android:layout_width="130dp"
   android:layout_height="35dp"
   android:layout_marginTop="23dp"
   android:text="Logout" />

I have looked for solutions and tried the Facebook tutorials, but I cant get it to work, so I am wondering is it possible to, when this button is clicked, to clear the login data from the app, and then redirect to the MainActivity? 我一直在寻找解决方案并尝试使用Facebook教程,但是我无法使其正常工作,所以我想知道是否有可能在单击此按钮时从应用程序清除登录数据,然后重定向到MainActivity?

This is what I have tried so far without success: 到目前为止,这是我一直未尝试的尝试:

Button s = (Button) findViewById(R.id.button_logout);
s.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
       Session session = Session.getActiveSession();
       session.closeAndClearTokenInformation();
       Intent intent = new Intent(SettingsActivity.this, MainActivity.class);
       startActivity(intent);
    }
});

Any help and tips are appreciated! 任何帮助和提示表示赞赏!

Try this: 尝试这个:

Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Session session = Session.getActiveSession();
if (session != null) {
    session.closeAndClearTokenInformation();
}

You should clear other user data saved in sharedPreferences, sqlite, etc... Maybe you should call to finish() when you call to startActivity 您应该清除保存在sharedPreferences,sqlite等中的其他用户数据。也许在调用startActivity时应该调用finish()

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

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