gpt4 book ai didi

Android Facebook api 3.0 错误 : Cannot call LoginActivity with a null calling package

转载 作者:IT老高 更新时间:2023-10-28 23:13:04 26 4
gpt4 key购买 nike

我正在尝试将一个 android 应用程序与新的 facebook 3.0 api 集成,但我得到了这个异常:

java.lang.RuntimeException: Unable to resume activity {dk.imu.konnekt/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.

我已搜索此错误,但似乎没有其他人对此有任何问题。我想这是因为我为每个选项卡使用了 TabHost 和 TabsGroupActivities。但我不知道如何解决它。

我在这里添加了相关代码:

public class MainTabActivity extends TabActivity {    
public void onCreate(Bundle savedInstanteState){
super.onCreate(savedInstanteState);
setContentView(R.layout.tab_layout);
TabHost tabHost = getTabHost();

View shareTab = getLayoutInflater().inflate(R.layout.share_tab, null);
tabHost.addTab(tabHost.newTabSpec("Share").setIndicator(shareTab)
.setContent(new Intent(MainTabActivity.this, ShareGroupActivity.class)));

...
}
}

-

public class ShareGroupActivity extends TabsGroupActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startChildActivity("ShareActivity", new Intent(this, ShareActivity.class));
}
}

-

public class ShareActivity extends BaseActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.share);

testFacebookConnection();
}

public void testFacebookConnection(){
Session session = new Session(this);
Session.setActiveSession(session);
SessionState state = session.getState();

Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

Session.StatusCallback statusCallback =
new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
Toast.makeText(ShareActivity.this, "Facebook session status changed", Toast.LENGTH_SHORT).show();
}
};

if (!session.isOpened() && !session.isClosed() && session.getState() != SessionState.OPENING) {
OpenRequest open = new OpenRequest(this).setCallback(statusCallback);
List<String> permission = new ArrayList<String>();
permission.add("publish_actions");
open.setPermissions(permission);
session.openForPublish(open);
} else {
Session.openActiveSession(this, true, statusCallback);
}
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
}

有什么解决办法吗?

更新 1 个堆栈跟踪:

FATAL EXCEPTION: main java.lang.RuntimeException: Unable to resume activity {dk.imu.konnekt/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:2812) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2851) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2234) at android.app.ActivityThread.access$600(ActivityThread.java:139) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261) at android.os.Handler.dispatchMessage(Handler.java:99) android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:4945) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) 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:110) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1236) at android.app.Activity.performResume(Activity.java:4613) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2796) ... 12 more

更新 2:看了下代码,找到了startChildActivity的实现:

public void startChildActivity(String Id, Intent intent) {     
Window window = getLocalActivityManager().startActivity(Id,intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if (window != null) {
mIdList.add(Id);
setContentView(window.getDecorView());
}
}

它使用标志 FLAG_ACTIVITY_CLEAR_TOP。我试图删除它,但结果没有改变。

更新 3:

https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/LoginActivity.java

Facebook 代码使用

callingPackage = getCallingPackage();

if (callingPackage == null) {
throw new FacebookException(NULL_CALLING_PKG_ERROR_MSG);
}

http://developer.android.com/reference/android/app/Activity.html#getCallingPackage()

这个方法有个说明:

If the calling activity is not expecting a result (that is it did not use the startActivityForResult(Intent, int) form that includes a request code), then the calling package will be null.

在 startChildActivity 方法中,我在扩展 ActivityGroup 的 TabsGroupActivity 中使用 getLocalActivityManager().startActivity 来处理选项卡 Activity 。 http://developer.android.com/reference/android/app/LocalActivityManager.html#startActivity(java.lang.String, android.content.Intent)

此方法与注释所说的不同。它不期望结果并且不使用 startActivityForResult 方法。该方法还确保类似于单实例启动模式。我应该如何更改此方法实现,以便它可以与 facebook 一起使用?

最佳答案

我设法找到了我的问题。虽然我没有设置

android:launchMode="singleTask"

我的 LoginActivity 有

android:noHistory="true"

导致该异常。我将 noHistory 设为 true 是因为我不希望用户在登录后的第一个 Activity 上按下返回按钮并返回登录屏幕。现在我需要找到另一个解决方案。

关于Android Facebook api 3.0 错误 : Cannot call LoginActivity with a null calling package,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14123580/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com