1

Possible Duplicate:
On Android, how do you switch activities programatically?

I have built an android application which allows user to login to facebook.For this I've used the faceboook-sdk package.Here is how I login:

    mFacebook = new Facebook(APP_ID);
    mAsyncRunner = new AsyncFacebookRunner(mFacebook);
 if(isSession()){
            Intent i = new Intent(getBaseContext(), com.SplashScreen.MultipleOptions.class);
            startActivity(i);
        }
            else
            {
                Log.d(TAG, "sessionNOTValid, relogin");
               mFacebook.authorize(this, PERMS, new LoginDialogListener());  

            }

And now LoginDialogListener:

 private class LoginDialogListener implements DialogListener {


        public void onComplete(Bundle values) {
                Log.d(TAG, "LoginONComplete");
                String token = mFacebook.getAccessToken();
                long token_expires = mFacebook.getAccessExpires();
                Log.d(TAG, "AccessToken: " + token);
                Log.d(TAG, "AccessExpires: " + token_expires);
                sharedPrefs = PreferenceManager
                                .getDefaultSharedPreferences(getBaseContext());
                sharedPrefs.edit().putLong("access_expires", token_expires)
                                .commit();
                sharedPrefs.edit().putString("access_token", token).commit();
                //mAsyncRunner.request("me", new IDRequestListener());

        }


        public void onFacebookError(FacebookError e) {
                Log.d(TAG, "FacebookError: " + e.getMessage());
        }


        public void onError(DialogError e) {
                Log.d(TAG, "Error: " + e.getMessage());
        }


        public void onCancel() {
                Log.d(TAG, "OnCancel");
        }
}

What I wanna do is-once I try to login and if login is succesfully then to move automaticaly to another activity. In this moment after succesfully log in I stay on the same activity.How do I do that???

Community
  • 1
  • 1
adrian
  • 4,574
  • 17
  • 68
  • 119
  • It's not duplicate...I don't know how to detect when the succefull login has been done ...or what gets fired when the login has been done so I could start an intent!! – adrian Jul 21 '11 at 10:19
  • Ah ok, I didn't get that from your question. I will add an answer. – THelper Jul 21 '11 at 11:21

1 Answers1

1

To detect a successfull login you can use an AuthListener, e.g.

SessionEvents.addAuthListener(new FacebookAuthListener());

public class FacebookAuthListener implements AuthListener {

    public void onAuthSucceed() {
        //... add code to switch activity here...
    }
THelper
  • 15,333
  • 6
  • 64
  • 104
  • What package do you use,facebook-sdk?and if u could please add a little bit more code I would be gratefull! – adrian Jul 21 '11 at 13:30
  • 1
    Yes, I'm using the Facebook-SDK. You should check out the "[simple example](https://github.com/facebook/facebook-android-sdk/tree/master/examples/simple)" project in this sdk. This contains both the SessionEvents class that you are probably looking for, as wel as a [complete example](https://github.com/facebook/facebook-android-sdk/blob/master/examples/simple/src/com/facebook/android/Example.java). – THelper Jul 21 '11 at 13:38