[英]Moving to next activity after successful facebook login
I have added the facebook login feature to my app. 我已经在我的应用程序中添加了Facebook登录功能。 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. 您只需要修复您的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: 在这里,您可以找到如何使用Intent启动新的Activity:
Android Dev - Starting Activity Android开发人员-开始活动
Intent intent = new Intent(CurrentActivity.this, NewActivity.class); startActivity(intent);
Be sure to define the Activity
you are switching to in AndroidManifest.xml
!! 确保在
AndroidManifest.xml
定义要切换到的Activity
!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.