简体   繁体   English

为什么我在与sdk 4.0.1集成的Facebook的下一个活动中没有获得注销按钮

[英]Why i didn't get Logout Button in Next Activity in Facebook Integration with sdk 4.0.1

I Login Successfully with Facebook Sdk 4.0.1 and goto second activity which is logout activity i click on logout button and redirected again to Main activity but actually i got there again Logout button which is my Login button which change to Logout by Facebook Sdk. 我成功使用Facebook Sdk 4.0.1登录并转到第二个活动即注销活动,我单击注销按钮,然后再次重定向到主活动,但实际上我又到达了注销按钮,这是我的登录按钮,由Facebook Sdk更改为注销。 So please tell me what's wrong with me. 所以,请告诉我我怎么了。 Please tell me how i get that Logout Button in my Next Activity 请告诉我我如何在下一个活动中获得退出按钮

 public class MainActivity extends FragmentActivity{ LoginButton loginButton; FacebookSdk mFacebook; private static final String[] PERMISSIONS = new String[] {"public_profile", "user_photos", "read_stream", "email" }; CallbackManager callbackManager; SharedPreferences preferences; String userName, emailId, userFacebookId, userId; URL image_value; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); setContentView(R.layout.activity_main); System.out.println("Inside onCreate "); preferences = getSharedPreferences("MyData", Context.MODE_WORLD_WRITEABLE); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setReadPermissions(PERMISSIONS); // If using in a fragment // loginButton.setFragment(); // Callback registration LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { SharedPreferences.Editor editor = preferences.edit(); editor.putString("accessToken", loginResult.getAccessToken().toString()); editor.apply(); GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) { try { System.out.println("Inside onSuccess "); userFacebookId = graphResponse.getJSONObject().getString("id"); userName = graphResponse.getJSONObject().getString("name"); emailId = graphResponse.getJSONObject().getString("email"); userId = graphResponse.getJSONObject().getString("link"); try { image_value = new URL("http://graph.facebook.com/" + userFacebookId + "/picture?type=large"); } catch (MalformedURLException e) { e.printStackTrace(); } SharedPreferences.Editor editor = preferences.edit(); editor.putString("userFacebookId", userFacebookId); editor.putString("userName", userName); editor.putString("emailId", emailId); editor.putString("userId", userId); editor.putString("image_value", image_value.toString()); editor.apply(); Intent intent = new Intent(MainActivity.this, logOut.class); startActivity(intent); } catch (org.json.JSONException e) { e.printStackTrace(); } } }); request.executeAsync(); } @Override public void onCancel() { System.out.println("Inside onCancel "); // App code } @Override public void onError(FacebookException exception) { System.out.println("Inside Error " + exception); // App code } }); } @Override public void onBackPressed() { super.onBackPressed(); finish(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode, resultCode, data); System.out.println("Inside onActivityResult "+resultCode); } } 

In second activity logout method,use following line to ask the LoginManager to logout as 在第二种活动注销方法中,使用以下行要求LoginManager以以下身份注销

LoginManager.getInstance().logOut();

So it will show "Login" text on facebook login button in your Main activity. 因此,它将在您的主要活动中的Facebook登录按钮上显示“登录”文本。

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

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