当我尝试使用以下代码向 Facebook 发布高分时,我收到此错误:
Invalid indirect reference 0x12341234 in decodeIndirectRef
在执行请求时发生错误。
Bundle params = new Bundle();
params.putString("score", "123");
Request postScoreRequest = new Request(session,
"/me/scores",
params,
HttpMethod.POST,
new Request.Callback() {
@Override
public void onCompleted(Response response) {
FacebookRequestError error = response.getError();
if (error != null) {
Log.d("test", "error: " + error);
} else {
Log.d("test", "success");
}
}
});
postScoreRequest.executeAsync();
上述 Java 代码是通过 JNI 从 C++ 调用的。我有许多与 Java JNI 方法类似的 C++,它们运行良好。我尝试在用户首次登录 Facebook 时运行上述高分提交代码(因此不涉及 JNI),但我没有看到崩溃。
为什么通过JNI调用上面的代码会报错?
编辑:我注意到这次崩溃发生在下一次从 C++ 到 Java 的 JNI 调用中。它可能与高分完全无关。如果我评论 postScoreRequest.executeAsync()
那么崩溃就会消失。我试图弄清楚那条线是如何影响 JNI 的。
编辑:在 UI 线程上显式创建和执行请求有效。我还是想明白为什么会这样。
最佳答案
假设您的 C++ 代码运行在与 UI 线程不同的线程上(因为它是游戏 -> 可能是 OpenGL -> Gl 渲染器启动它自己的线程):您的 Java 线程也不在UI 线程和 Facebook 的 executeAsync
应该在 UI 线程上运行:
https://developers.facebook.com/docs/reference/android/3.0/class/Request/#executeAsync%28%29
executeAsync() Executes this request and returns the response. This should only be called from the UI thread.
附言要修复它,我会调用 runOnUiThread
关于android - 从 Android 应用程序向 Facebook 提交高分时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27134685/