我正在按照本教程集成 Facebook SDK for Android。它完美地工作。我的问题是,如果我想退出 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
。任何人都可以帮忙吗?提前致谢。