當我運行我的Android應用程序並單擊批准以授予權限時,它不會重定向到MainActivity。 「登錄」消息沒有出現在Catlog中。我已閱讀Facebook開發人員指南,並在Stack中將我的代碼與不同的主題進行比較。我看不出我做錯了什麼。登錄按鈕facebook android不會重定向到新活動
我會很樂意的幫助。
public class Login extends Activity {
/**
* Called when the activity is first created.
*/
private CallbackManager callbackManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_login);
final CallbackManager callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions("public_profile", "email", "user_friends");
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Intent i = new Intent(Login.this, MainActivity.class);
startActivity(i);
System.out.print("Logged in");
}
@Override
public void onCancel() {
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
Log.i("Error" , "Error");
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
堆棧跟蹤
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=-1, data=Intent { (has extras) }} to activity {org.MYapp.FBtestApp/org.MYapp.FBtestApp.Login}: java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.facebook.CallbackManager.onActivityResult(int, int, android.content.Intent)' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:3974)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4017)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'boolean com.facebook.CallbackManager.onActivityResult(int, int, android.content.Intent)' on a null object reference
at org.MYapp.FBtestApp.Login.onActivityResult(Login.java:98)
當您僅提供代碼時,很難爲您提供幫助。 logcat中是否有錯誤?有參數是空的(特別是「resultCode」和「數據」)? –
我建議你在問問題時不要*更新你的代碼。現在接受的答案不再有意義。 – tir38