简体   繁体   中英

Moving to next activity after successful facebook login

I have added the facebook login feature to my app. It works if you login once and give you the user token. However I want it to move to the next activity.

I know I have a typo activity wrong in the test activity. Once logged in the app crashes straight away. The code is below, any ideas?

public class LoginActivity extends AppCompatActivity {

LoginButton loginButton;
TextView loginStatusText;
CallbackManager callbackManager;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);
    loginButton = (LoginButton)findViewById(R.id.fb_login_bn);
    loginStatusText = (TextView)findViewById(R.id.loginStatusText);
    callbackManager = CallbackManager.Factory.create();
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            //What happens when the user logs in.

           // loginStatusText.setText("Login Sucessfull \n" + loginResult.getAccessToken().getUserId() + "\n" +loginResult.getAccessToken().getToken());
            Intent testactivty = new Intent("uk.co.cyclesavy.cyclesavy.TestActivty");
            startActivity(testactivty);


        }

        @Override
        public void onCancel() {

            loginStatusText.setText("Login Cancelled");
        }

        @Override
        public void onError(FacebookException error) {

        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  callbackManager.onActivityResult(requestCode,resultCode,data);
}

}

You just need to fix your Intent.

Instead of

Intent testactivty = new Intent("uk.co.cyclesavy.cyclesavy.TestActivty");

Try

Intent intent = new Intent(LoginActivity.this, TestActivity.class);

Here you can find how to start a new Activity with Intent:

Be sure to define the Activity you are switching to in AndroidManifest.xml !!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM