在我的活动课程中,我无法使用“this”打开请求或设置活动会话。我的活动是另一个活动的子活动,这似乎是它与 facebook 提供的登录示例之间的唯一区别。当我使用“this”时,出现此错误:
05-24 12:24:27.101: E/AndroidRuntime(30006): FATAL EXCEPTION: main
05-24 12:24:27.101: E/AndroidRuntime(30006): java.lang.RuntimeException: Unable to resume activity {com.tsavomedia.babynames/com.facebook.LoginActivity}: com.facebook.FacebookException: Cannot call LoginActivity with a null calling package. This can occur if the launchMode of the caller is singleInstance.
05-24 12:24:27.101: E/AndroidRuntime(30006): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2742)
05-24 12:24:27.101: E/AndroidRuntime(30006): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2771)
05-24 12:24:27.101: E/AndroidRuntime(30006): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2235)
05-24 12:24:27.101: E/AndroidRuntime(30006): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-24 12:24:27.101: E/AndroidRuntime(30006): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-24 12:24:27.101: E/AndroidRuntime(30006): at android.os.Handler.dispatchMessage(Handler.java:99)
05-24 12:24:27.101: E/AndroidRuntime(30006): at android.os.Looper.loop(Looper.java:137)
05-24 12:24:27.101: E/AndroidRuntime(30006): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-24 12:24:27.101: E/AndroidRuntime(30006): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 12:24:27.101: E/AndroidRuntime(30006): at java.lang.reflect.Method.invoke(Method.java:511)
05-24 12:24:27.101: E/AndroidRuntime(30006): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-24 12:24:27.101: E/AndroidRuntime(30006): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-24 12:24:27.101: E/AndroidRuntime(30006): at dalvik.system.NativeStart.main(Native Method)
05-24 12:24:27.101: E/AndroidRuntime(30006): Caused by: com.facebook.FacebookException: Cannot call LoginActivity with a null calling package. This can occur if the launchMode of the caller is singleInstance.
05-24 12:24:27.101: E/AndroidRuntime(30006): at com.facebook.LoginActivity.onResume(LoginActivity.java:110)
05-24 12:24:27.101: E/AndroidRuntime(30006): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1185)
05-24 12:24:27.101: E/AndroidRuntime(30006): at android.app.Activity.performResume(Activity.java:5182)
05-24 12:24:27.101: E/AndroidRuntime(30006): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2732)
05-24 12:24:27.101: E/AndroidRuntime(30006): ... 12 more
我尝试在其位置使用 getParent() 但是页面重定向到父级并且不调用回调。是否有我不能使用它的原因以及修复它的方法?
编辑:代码
这是单击按钮登录 facebook 后调用的内容:
public void getEmail() {
StatusCallback callback = new StatusCallback() {
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
sendRequests();
} else if (exception != null) {
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(getParent()).create();
alertDialog.setTitle(getParent().getString(R.string.login_fail));
alertDialog.setMessage(exception.getMessage());
alertDialog.show();
mSession = createSession();
}
}
};
Session session = Session.getActiveSession();
if (session == null) {
session = new Session(this);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED) || session.getState().equals(SessionState.CREATED)) {
session.addCallback(callback);
session.openForRead(new OpenRequest(this));
Session.setActiveSession(session);
}
} else {
Session.openActiveSession(this, true, callback);
}
}