Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebook Android SDK - When using UiLifecycleHelper, should I use Activity or Application for context?
    text
    copied!<p>Hi I am currently using Facebook SDK 3.0 for Android. Here are some facts first.</p> <ul> <li><p>Instead of putting my app_id in AndroidManifest.xml, I set that value in my java code programmatically. Hence I use something like the following helper methods when dealing with session.</p> <pre><code>if (session == null || session.isClosed()) { String applicationId = Persistent.getString(null, SocialUtil.FACEBOOK_APP_ID); session = new Session.Builder(Utils.ctx).setApplicationId(applicationId).build(); Session.setActiveSession(session); } </code></pre></li> <li><p>Once the user logs in with facebook, the session is used in many activities and that's why I provided application context for session. </p></li> </ul> <p>As you see for the context of session, I provide Utils.ctx which is an Application Object. Since Facebook SDK's native UiLifecycleHelper creates sesssion with Activity when session doesn't exist, I created my own FBIUiLifecycleHelper by coping the original UiLifeCycleHelper and just switching</p> <pre><code> session = new Session(activity); </code></pre> <p>to </p> <pre><code> String applicationId = Persistent.getString(null, SocialUtil.FACEBOOK_APP_ID); session = new Session.Builder(Utils.ctx).setApplicationId(applicationId).build(); </code></pre> <p>.</p> <p>However, it seems like whenever Session state changes in my activity, the callback function is NOT called at all. I think it is because I used application context instead of activity context when dealing with session.</p> <p>MY QUESTION IS, 1. how is it different when you provide application context or activity context for session's context? 2. Which one is a recommened practice when? why? 3. Let's say a user login created a session with activity context. Once this session is set to by setActiveSession(), can this session be used in other activites by calling getActiveSession()? Maybe I don't really have to use application context for session context?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload