我正在关注整合Facebook SDK for Android的this教程。它完美地运作。我的问题是,如果我想退出Facebook(如关闭会话)该怎么办。如何登录并注销相同的按钮。
button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i=new Intent(this,MainActivity.class);
startActivity(i);
}
});
以下是我的代码:
public class MainActivity extends Activity {
private Button button1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Session.openActiveSession(this, true, new StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
// TODO Auto-generated method stub
Request.executeMeRequestAsync(session,new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
// TODO Auto-generated method stub
if(user!=null){
TextView tv1=(TextView)findViewById(R.id.textview1);
tv1.setText("Hello "+user.getName()+ ";");
}
}
});
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
}
我想登录并注销buttonClick
。有人可以帮忙吗?
提前谢谢。
答案 0 :(得分:0)
调用此方法。您将从会话中退出
session.closeAndClearTokenInformation();