我正在尝试使用 facebook sdk 登录。下面的代码假设更改TextView
登录或注销的值,但是当我运行它时,我只是得到一个空白屏幕。setText()
没有运行。请问有什么帮助吗?
public class MainActivity extends Activity {
TextView T;
private boolean isResumed = false;
private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback =
new Session.StatusCallback() {
@Override
public void call(Session session,
SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
T=(TextView)findViewById(R.id.myname);
}
private void onSessionStateChange(Session session, SessionState state, Exception
exception)
{
// Only make changes if the activity is visible
if (state.isOpened())
{
// If the session state is open:
// Show the authenticated fragment
T.setText(" logged in");
}
if (state.isClosed())
{
// If the session state is closed:
// Show the login fragment
T.setText(" logged out");
}
}
@Override
public void onResume() {
super.onResume();
uiHelper.onResume();
isResumed = true;
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
isResumed = false;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
}