基本上我想在MainActivity启动的Dialog中使用LoginButton。
已编辑日志:
每次打开对话框,app崩溃和onActivityResult抛出:
01-22 12:20:59.775: E/AndroidRuntime(31017): FATAL EXCEPTION: main
01-22 12:20:59.775: E/AndroidRuntime(31017): Process: net.lagsoft.trivioliv2, PID: 31017
01-22 12:20:59.775: E/AndroidRuntime(31017): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=998, result=0, data=null} to activity {net.lagsoft.trivioliv2/net.lagsoft.trivioliv2.MainScreen}: java.lang.ClassCastException: android.view.ContextThemeWrapper cannot be cast to android.app.Activity
01-22 12:20:59.775: E/AndroidRuntime(31017): at android.app.ActivityThread.deliverResults(ActivityThread.java:3365)
01-22 12:20:59.775: E/AndroidRuntime(31017): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3408)
01-22 12:20:59.775: E/AndroidRuntime(31017): at android.app.ActivityThread.access$1300(ActivityThread.java:135)
01-22 12:20:59.775: E/AndroidRuntime(31017): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
01-22 12:20:59.775: E/AndroidRuntime(31017): at android.os.Handler.dispatchMessage(Handler.java:102)
01-22 12:20:59.775: E/AndroidRuntime(31017): at android.os.Looper.loop(Looper.java:136)
01-22 12:20:59.775: E/AndroidRuntime(31017): at android.app.ActivityThread.main(ActivityThread.java:5017)
01-22 12:20:59.775: E/AndroidRuntime(31017): at java.lang.reflect.Method.invokeNative(Native Method)
01-22 12:20:59.775: E/AndroidRuntime(31017): at java.lang.reflect.Method.invoke(Method.java:515)
01-22 12:20:59.775: E/AndroidRuntime(31017): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
01-22 12:20:59.775: E/AndroidRuntime(31017): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
01-22 12:20:59.775: E/AndroidRuntime(31017): at dalvik.system.NativeStart.main(Native Method)
01-22 12:20:59.775: E/AndroidRuntime(31017): Caused by: java.lang.ClassCastException: android.view.ContextThemeWrapper cannot be cast to android.app.Activity
01-22 12:20:59.775: E/AndroidRuntime(31017): at com.facebook.widget.LoginButton.onActivityResult(LoginButton.java:440)
01-22 12:20:59.775: E/AndroidRuntime(31017): at net.lagsoft.trivioliv2.MainScreen.onActivityResult(MainScreen.java:1651)
01-22 12:20:59.775: E/AndroidRuntime(31017): at android.app.Activity.dispatchActivityResult(Activity.java:5423)
01-22 12:20:59.775: E/AndroidRuntime(31017): at android.app.ActivityThread.deliverResults(ActivityThread.java:3361)
01-22 12:20:59.775: E/AndroidRuntime(31017): ... 11 more
onActivityResult():
@Override
protected void onActivityResult(int requestCode, int resultCode,Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
对话代码:
Dialog dialog = new Dialog(MainScreen.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.dialog_options_menu); dialog.setCancelable(false);
dialog.show();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.getWindow().setGravity(Gravity.TOP);
LoginButton lButton =(LoginButton)dialog.findViewById(R.id.activity_login_facebook_btn_login);
它好像在facebook回调上的activityresult因为它在对话框中而返回损坏或空。 (LoginButton来自活动)。如何解决这个问题?
答案 0 :(得分:2)
将onActivityResult()
改为喜欢这个
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
答案 1 :(得分:1)
Session.getActiveSession()
返回null
- 这是您onActivityResult()
中NPE的唯一途径。
问题上没有足够的背景来说明为什么它会返回null
。