Redirect to an new Activity after login in to Facebook (Facebook SDK 3.5.2)

+2 votes
asked Nov 19, 2013 by dmt82

I have two classes that is for Facebook login, and it works. I can press the Loginbutton, write in my username/password and it will log me in, BUT the thing is that I will come back to the Main-class (startsite) with my logo picture and so on.

What I want to do is, when you pressed the loginbutton and logged in, you will be redirected to a new Activity

Here is my 2 Classes you can see, but where do I do the redirect? Read on StackOverflow about the "onComplete" but I cant make it, think its because I use SDK 3.5.2 and not 2.0. So How can i make a redirect to a new Activity after success login.

My MainActivity:

public class SocialLoginActivity extends FragmentActivity {

private SocialLoginFragment socialLoginFragment;

public void onCreate(Bundle savedInstanceState) {

    if (savedInstanceState == null) {
        // Add the fragment on initial activity setup
        socialLoginFragment = new SocialLoginFragment();
                .add(, socialLoginFragment).commit();
    } else {
        // Or set the fragment from restored state info
        socialLoginFragment = (SocialLoginFragment) getSupportFragmentManager()


And here is the FragmentClass:

public class SocialLoginFragment extends Fragment {

private static final String TAG = "SocialLoginFragment";
private UiLifecycleHelper uiHelper;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_social_login, container,
    LoginButton authButton = (LoginButton) view
    // authButton.setReadPermissions(Arrays.asList("name", "user_birthday",
    // "friends_birthday"));

    return view;

private void onSessionStateChange(Session session, SessionState state,
        Exception exception) {
    if (state.isOpened()) {
        Log.i(TAG, "Logged in...");
    } else if (state.isClosed()) {
        Log.i(TAG, "Logged out...");

public void onCreate(Bundle savedInstanceState) {
    uiHelper = new UiLifecycleHelper(getActivity(), callback);

private Session.StatusCallback callback = new Session.StatusCallback() {
    public void call(Session session, SessionState state,
            Exception exception) {
        onSessionStateChange(session, state, exception);

public void onResume() {

    Session session = Session.getActiveSession();
    if (session != null && (session.isOpened() || session.isClosed())) {
        onSessionStateChange(session, session.getState(), null);

public void onPause() {

public void onDestroy() {

public void onSaveInstanceState(Bundle outState) {

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);



enter image description here

1 Answer

+5 votes
answered Nov 19, 2013 by ming-li

The error you see is because a Fragment is not a Context object. You need to get the parent activity, something like:

Intent intent = new Intent(getActivity(), MainActivity.class);
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter