-1

I have an activity A that has no specified launchMode and that uses the Facebook SDK to login.

Activity A starts activity B, which is launch mode singleTop.

Somehow, I'm running into this error periodically on resume, in rather rare circumstances.

Any thoughts on what this could be? I'm not entirely understanding how I could be hitting this if I'm not making any Facebook SDK calls from any activity that has a launch mode specified. All the other stuff I've run down on this error involves a pretty straightforward interpretation of this error text, which this doesn't seem to be.

This only happens onResume. To be extra clear, in the normal course of the activity, everything works just fine, the facebook login window launches fine, etc.

In my manifest I do have:

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

and the launching activity as

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

The error text:

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)
secureboot
  • 1,776
  • 4
  • 20
  • 32

3 Answers3

5

I ran into this problem, as well. If you look into the facebook source for the LoginActivity you will find the following comment:

    // 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;
    }

If you adjust your manifest (AndroidManifest.xml) to something other than 'singleInstance' (I chose standard -- the differences are outlined here):

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

to:

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

then authentication proceeded as normal!

Muad'Dib
  • 511
  • 4
  • 11
0

I had the same error. I used singleton. Error for me was that instance of activity was not the same. I add next

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;
}

And it work

user1139714
  • 61
  • 1
  • 5
-3

just declare this Activity to your manifest.xml file

     <activity
        android:name="com.facebook.LoginActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
  • 1
    Updated the question to make it clearer that this is in there. Without this part, it would never work, not just fail to work in onResume. – secureboot Jan 21 '14 at 16:31