Facebook为android,为什么我不能使用'this'作为openRequest()的活动? [英] Facebook for android, why can't I use 'this' as the activity to openRequest()?
问题描述
在我的活动类中,我无法使用'this'打开请求或设置活动会话。我的活动是另一项活动的一个孩子,这似乎是Facebook和Facebook提供的登录示例之间的唯一区别。当我使用'这''我得到这个错误:
In my activity class I am unable to open a request or set active session using 'this'. My activity is a child of another activity and that seems to be the only difference between it and the login sample given by facebook. When I use 'this' I get this error:
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 ),但该页面重定向到父级,不调用回调。有没有理由不能使用这种方法来解决它?
I have tried using getParent() in its place however the page redirects to the parent and does not call the callback. Is there a reason I cannot use this and a way to fix it?
编辑:代码
这是点击按钮登录到Facebook后,调用什么?
This is what gets called once the button is clicked to login to 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);
}
}
推荐答案
错误日志说:...调用者是singleInstance。
the error log says : ...the caller is singleInstance.
也许同样的问题:更新 - Android Facebook api 3.0错误:无法使用空调用包调用LoginActivity
这篇关于Facebook为android,为什么我不能使用'this'作为openRequest()的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!