Note that there are some explanatory texts on larger screens.

plurals
  1. POManage Facebook Session in Activity
    primarykey
    data
    text
    <p>So I have the facebook login fragment setup, but because I am building a mutli-tab+swipe app with SectionsPagerAdapter, I built the login (splash screen) into a new activity. How do I manage the session now that its in a activity?</p> <p>EDIT</p> <p>What I have moved to doing is putting the session items in SessionActivity and extending by all activities that use it. I then setup a login activity and made that my main entry point.</p> <pre><code>public class SessionActivity extends FragmentActivity { private static final String TAG = "SessionActivity"; protected UiLifecycleHelper uiHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); } public Session.StatusCallback callback = new Session.StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { onSessionStateChange(session, state, exception); } }; protected void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { Log.i(TAG, "Logged in..."); Toast.makeText(this, "Logged in...", Toast.LENGTH_LONG).show(); //Intent intent = new Intent(this, MainActivity.class); //startActivity(intent); //finish(); } else if (state.isClosed()) { Log.i(TAG, "Logged out..."); Toast.makeText(this, "Logged out...", Toast.LENGTH_LONG).show(); } } @Override public void onResume() { super.onResume(); // For scenarios where the main activity is launched and user // session is not null, the session state change notification // may not be triggered. Trigger it if it's open/closed. Session session = Session.getActiveSession(); if (session != null &amp;&amp; (session.isOpened() || session.isClosed()) ) { onSessionStateChange(session, session.getState(), null); } uiHelper.onResume(); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); uiHelper.onActivityResult(requestCode, resultCode, data); } @Override public void onPause() { super.onPause(); uiHelper.onPause(); } @Override public void onDestroy() { super.onDestroy(); uiHelper.onDestroy(); } @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); uiHelper.onSaveInstanceState(outState); } </code></pre> <p>}</p> <p>My login as the main entry point for the app. This way the session is kickstarted once the user logs in.</p> <pre><code>public class FacebookActivity extends SessionActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); } </code></pre> <p>}</p> <p>At this point the onSessionStateChange should handle showing the login screen or the the working activity, however I'm getting stuck in a infinity loop opening and closing the login in this example.</p> <pre><code> protected void onSessionStateChange(Session session, SessionState state, Exception exception) { if (state.isOpened()) { Log.i(TAG, "Logged in..."); Toast.makeText(this, "Logged in...", Toast.LENGTH_LONG).show(); //Intent intent = new Intent(this, MainActivity.class); //startActivity(intent); //finish(); } else if (state.isClosed()) { Log.i(TAG, "Logged out..."); Toast.makeText(this, "Logged out...", Toast.LENGTH_LONG).show(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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