-1

我正在尝试使用 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);
}

}

4

1 回答 1

0

您似乎忘记了开始登录过程。
你需要打电话

Session.openActiveSession(this, true, callback);

在 onCreate 方法或您喜欢的任何地方进行异常处理。

希望这可以帮助。

于 2014-01-04T08:42:40.930 回答