0

I have developed an android application with TabGroupActivity (See this for example) and everything works fine except Social Networking integration like Facebook and Twitter.

This Error was recorded in Stackoverflow before here and here and here

java.lang.RuntimeException: Unable to resume activity {com.xxxx.xxxxx/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.

07-29 18:22:55.757: E/AndroidRuntime(2342): Caused by: com.facebook.FacebookException: Cannot call LoginActivity with a null calling package. This can occur if the launchMode of the caller is singleInstance.

P.S:Everything worked fine before implementing TabGroupActivity

UPDATE 1: In the Manifest file i updated the code as follows as:

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

But the Exception still gives: the launchMode of the caller is singleInstance

Why So..??

UPDATE 2: Now I kept debugging points inside LoginActivity of Facebook SDK. In that for getCallingPackage(), I get Null

String callingPackage = getCallingPackage();//Always Null


BackTracing it: On the Calling Activity (FacebookShare.java), I always get data as null instead of some values.

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
        //Toast.makeText(FacebookShareActivity.this, "onActivityResult", Toast.LENGTH_SHORT).show();
    }

Can anyone explain this behavior..?? I have been stuck on this from days.

Community
  • 1
  • 1
Name is Nilay
  • 2,743
  • 4
  • 35
  • 77
  • what u r doning???i mean to u want to do only sharing on social sites?? – Jelly Bean Jul 29 '13 at 10:27
  • @JellyBean-Yes..I have some info which i want to share in with facebook(means update my status). And everything perfectly fine before implementing TabGroupActivity..so wat could be the solution ?? – Name is Nilay Jul 29 '13 at 10:48

3 Answers3

2

Paste this code.It is working on those applications install in ur phone.

 void share(String nameApp, String imagePath) {
            try
            {
                List<Intent> targetedShareIntents = new ArrayList<Intent>();
                Intent share = new Intent(android.content.Intent.ACTION_SEND);
                share.setType("image/jpeg");
                List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(share, 0);
                if (!resInfo.isEmpty()){
                    for (ResolveInfo info : resInfo) {
                        Intent targetedShare = new Intent(android.content.Intent.ACTION_SEND);
                        targetedShare.setType("image/jpeg"); // put here your mime type
                        if (info.activityInfo.packageName.toLowerCase().contains(nameApp) || info.activityInfo.name.toLowerCase().contains(nameApp)) {
                            targetedShare.putExtra(Intent.EXTRA_SUBJECT, "Sample Photo");
                         targetedShare.putExtra(Intent.EXTRA_TEXT,"This photo is created by App Name");
                            targetedShare.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)) );
                            targetedShare.setPackage(info.activityInfo.packageName);
                            targetedShareIntents.add(targetedShare);
                        }
                    }
                    Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
                    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
                    startActivity(chooserIntent);
                }
            }
            catch(Exception e){
                 Log.v("VM","Exception while sending image on" + nameApp + " "+  e.getMessage());
             }
            }
thepoosh
  • 12,497
  • 15
  • 73
  • 132
Jelly Bean
  • 137
  • 10
  • No..I cant make it work like this..I already have buttons for Facebook, Twitter, etc..Can u suggest me some other solution please...see my updated post. – Name is Nilay Jul 29 '13 at 11:22
1

Last time i had this error, it was because i launched facebook's LoginActivity with wrong parameters, use this part of xml:

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

I had this error when i launched LoginActivity with launchMode singleInstance (or something like that). Check this out.

Edit: I have one more thought... when you try to call facebook pass context not of local activity (one in tab), but try to pass context of parent activity (it will be TagGroupActivity).

Drake29a
  • 896
  • 8
  • 23
  • I got following exception:07-29 16:27:04.225: E/AndroidRuntime(7461): java.lang.RuntimeException: Unable to resume activity {com.xxxx.xxx/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. – Name is Nilay Jul 29 '13 at 10:53
  • On the ManifestFile:: – Name is Nilay Jul 29 '13 at 11:03
  • context was only passed here:this.session.openForRead(new Session.OpenRequest(this.getParent()) .setCallback(callback));...where I used this.getParent() as u can see...but still same error !!! – Name is Nilay Jul 29 '13 at 12:25
0
<activity
  android:name="xx.yy.YourActivity"
  android:launchMode="singleTask"
/>

(try singleTask instead of singleInstance) I had the same issue in the past, but I rechecked my manifest and cant find any launchMode there.

Eugene Pinchuk
  • 546
  • 3
  • 14