Facebook SDK for android - How to share Session throughout all activities

A problem which I faced when using Facebook SDK for android was in my app login happens through one activity and posting to Facebook happens through another activity. So I had to retrieve the session which is opened in the LoginActitvity. Actually solution was simpler than I thought. To get the session from an another activity you can use the below method.

private void getSession() {
     Session.openActiveSession(this, false, callback);
}

private Session.StatusCallback callback = new Session.StatusCallback() {
     public void call(Session session, SessionState state,
              Exception exception) {
         if (session.isOpened()) {
             //Do something
         }
     }
};


Comments

Popular posts from this blog

Fixing Error "Failed to load VMMR0.r0 (VERR_SUPLIB_WORLD_WRITABLE)" in Virtualbox

Create new Java Class files at runtime

Using iReport plugin for Jasper Reports in Netbeans