public void setSession ( Session newSession ) { if ( newSession == null ) { if ( session != null ) { // We're current tracking a Session. Remove the callback // and start tracking the active Session. session . removeCallback ( callback ) ; session = null ; addBroadcastReceiver ( ) ; if ( getSession ( ) != null ) { getSession ( ) . addCallback ( callback ) ; } } } else { if ( session == null ) { // We're currently tracking the active Session, but will be // switching to tracking a different Session object. Session activeSession = Session . getActiveSession ( ) ; if ( activeSession != null ) { activeSession . removeCallback ( callback ) ; } broadcastManager . unregisterReceiver ( receiver ) ; } else { // We're currently tracking a Session, but are now switching // to a new Session, so we remove the callback from the old // Session, and add it to the new one. session . removeCallback ( callback ) ; } session = newSession ; session . addCallback ( callback ) ; } }
Set the Session object to track .