2016-12-05 62 views
0

我想在清理Facebook時清理我的userinfo textview。但我不知道我實際註銷了哪一部分。並不知道我需要清理信息(名字,姓氏)有什麼想法?提前致謝。清理信息Facebook登出

MainActivity.java

public class LoginActivity extends AppCompatActivity { 

private TextView userinfo; 
private CallbackManager callbackManager; 
private LoginButton loginButton; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    FacebookSdk.sdkInitialize(getApplicationContext()); 
    LoginManager.getInstance().logOut(); 
    setContentView(R.layout.activity_login); 
    callbackManager = CallbackManager.Factory.create(); 
    loginButton = (LoginButton)findViewById(R.id.login_button); 
    userinfo= (TextView) findViewById(R.id.textView); 
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { 
     @Override 
     public void onSuccess(LoginResult loginResult) 
     { 

      Toast.makeText(LoginActivity.this,"Oturum başarı ile açıldı!",Toast.LENGTH_LONG).show(); 
      setFacebookData(loginResult); 


     } 

     @Override 
     public void onCancel() { 
      Toast.makeText(LoginActivity.this,"Giriş işlemi iptal edildi.",Toast.LENGTH_LONG).show(); 
     } 

     @Override 
     public void onError(FacebookException error) { 

      Toast.makeText(LoginActivity.this,"Giriş başarısız.",Toast.LENGTH_LONG).show(); 
     } 

    }); 






} 

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

private void setFacebookData(final LoginResult loginResult) 
{ 
    GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { 
     @Override 
     public void onCompleted(JSONObject object, GraphResponse response) 
     { 
      try { 


       String firstName = response.getJSONObject().getString("first_name"); 
       String lastName = response.getJSONObject().getString("last_name"); 
       Log.i("Login"+ "FirstName", firstName); 
       Log.i("Login" + "LastName", lastName); 
       userinfo.setText("Hoşgeldiniz, "+firstName + " " +lastName+"!"); 



      } 
      catch (JSONException e) { 
       e.printStackTrace(); 
      } 
     } 
    }); 
    Bundle parameters = new Bundle(); 
    parameters.putString("fields", "first_name,last_name"); 
    request.setParameters(parameters); 
    request.executeAsync(); 

} 

回答

0

如果您正在使用FB sdk按鈕,那麼它會將用戶註銷到其點擊位置。否則在你點擊按鈕,只需要調用

LoginManager.getInstance().logOut(); 

默認情況下將應用這些命令

AccessToken.setCurrentAccessToken(null); 
Profile.setCurrentProfile(null); 

&您可以通過設置「」(例如textview.setText(「」)清除您textviews; )

+0

我可以在registercallback函數結束時使用settext嗎? –

0

如你不存儲無論是在sharedPref或數據庫名字或姓氏也沒有必要以清除任何數據只要設置的TextView:

userinfo.setText(""); 
+0

我應該這樣做onCreate()? –

+0

沒有當你點擊註銷按鈕! –