How to use a session session when moving from one action to another

I have two operations: MainActivity and Menu. I have been using my main activity to login to facebook successfully and have configured the necessary input stream. However, I would like to be able to use the session and state in the Activity Menu. So, to do this, I used Intent and putExtra to send the session to the Activity Menu, but I'm not sure how to use this session there.

This is my MainActivity (this is where I have the login logic and transfer the session to the Menu):

public class MainActivity extends Activity {

 ....some more login logic is here....

private void onSessionStateChange(Session session, SessionState state,
        Exception exception) {
    if (session != currentSession) {
        return;
    }

    if ((session != null && session.isOpened())) {
        finish();

        Intent menu = new Intent(getApplicationContext(), Menu.class);
        menu.putExtra("facebookSession", session);
        startActivity(menu);

    } else if (state.isClosed()) {


    }
}
}

and this action is on the menu (where I get the session sent via Intent):

public class Menu extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);
    Bundle extras = getIntent().getExtras();
    if (extras != null) {           
        Session.setActiveSession((Session) extras.getSerializable("facebookSession"));
    }

}

}

Now, how can I use this past session to say “log the user out” I want to try and do this in the menu activity when the logout button is pressed:

logout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Log user out by using session i got from MainActivity
            if (currentSession != null) {
                currentSession.closeAndClearTokenInformation();
            }
        }
    });

Thanks for the help.

+1
1

, , , MenuActivity, MenuActivity

logout.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        Session.getActiveSession().closeAndClearTokenInformation();
    }
});
+2

All Articles