Facebook登录 - 无法使用null调用包调用LoginActivity

时间:2014-01-21 07:05:22

标签: android facebook

我有一个没有指定launchMode且使用Facebook SDK登录的活动A.

活动A启动活动B,即启动模式singleTop。

不知何故,我在恢复时会定期遇到此错误,在极少数情况下。

关于这可能是什么的任何想法?如果我没有从任何指定了启动模式的活动中进行任何Facebook SDK调用,我并不完全理解如何实现这一点。我在此错误中遇到的所有其他内容都涉及对此错误文本的非常直接的解释,这似乎并非如此。

这只发生在theResume上。为了更加清楚,在活动的正常过程中,一切正常,facebook登录窗口启动正常,等等。

在我的清单中我确实有:

<activity android:name="com.facebook.LoginActivity"/>

和启动活动

<activity android:name="mypackage.login.SocialLoginActivity" android:screenOrientation="portrait">

错误文字:

java.lang.RuntimeException: Unable to resume activity {mypackage/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.
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2639)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2667)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2140)
       at android.app.ActivityThread.access$700(ActivityThread.java:140)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4921)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: com.facebook.FacebookException: Cannot call LoginActivity with a null calling package. This can occur if the launchMode of the caller is singleInstance.
       at com.facebook.LoginActivity.onResume(LoginActivity.java:111)
       at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1199)
       at android.app.Activity.performResume(Activity.java:5280)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2629)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2667)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2140)
       at android.app.ActivityThread.access$700(ActivityThread.java:140)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4921)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
       at dalvik.system.NativeStart.main(NativeStart.java)

3 个答案:

答案 0 :(得分:5)

我也遇到了这个问题。如果你查看LoginActivity的facebook源代码,你会发现以下评论:

    // If the calling package is null, this generally means that the callee was started
    // with a launchMode of singleInstance. Unfortunately, Android does not allow a result
    // to be set when the callee is a singleInstance, so we log an error and return.
    if (callingPackage == null) {
        Log.e(TAG, NULL_CALLING_PKG_ERROR_MSG);
        finish();
        return;
    }

如果您将清单(AndroidManifest.xml)调整为“singleInstance”之外的其他内容(我选择标准 - the differences are outlined here):

<activity
  android:name="com.your.package.YourActivity"
  android:label="@string/app_name"
  android:launchMode="singleInstance" >

为:

<activity
  android:name="com.your.package.YourActivity"
  android:label="@string/app_name"
  android:launchMode="standard" >

然后认证正常进行!

答案 1 :(得分:0)

我有同样的错误。我用过单身人士。我的错误是活动的实例不一样。我添加下一个

public static FacebookManager getInstance(Activity activity){
        if (mInstance==null)
            synchronized (FacebookManager.class) {
                if (mInstance==null)
                    mInstance=new FacebookManager(activity);
            }
        if (activity!=null&&!mInstance.mActivity.equals(activity))
            mInstance.mActivity=activity;
        return mInstance;
}

它的工作

答案 2 :(得分:-3)

将此活动声明为您的manifest.xml文件

     <activity
        android:name="com.facebook.LoginActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />