facebook sdk login for android?

117 views Asked by At

I am trying to use the facebook sdk to log in. The code below is suppose to change the value of the TextView to logged in or logged out but when i run it i just get a blank screen. The setText() are not being run. Any help please?

    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);
}

}

1

There are 1 answers

1
Tanmay Patil On

It seems you have forgotten to start login process.
You need to call

Session.openActiveSession(this, true, callback);

with exception handling in the onCreate method or wherever you like.

Hope this helps.