java.lang.RuntimeException:使用 Facebook 登录时无法传递结果 ResultInfo [英] java.lang.RuntimeException: Failure delivering result ResultInfo while logging using Facebook

查看:16
本文介绍了java.lang.RuntimeException:使用 Facebook 登录时无法传递结果 ResultInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在模拟器上运行良好.所以我决定在我的 Android 手机上运行我的应用程序.我正在尝试使用我的应用程序登录 Facebook 帐户,它在模拟器上运行良好.一旦我在 android 手机上运行我的应用程序,我总是会遇到这个异常-

My application is working fine on emulator. So I decided to run my application on my Android phone. I am trying to login to Facebook account using my application and it works fine on emulator. And as soon as I run my application on android phone I always get this exception-

01-30 11:06:08.400: E/AndroidRuntime(7463): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=0, data=null} to activity {com.facebook.samples.sessionlogin/com.facebook.LoginActivity}: java.lang.NullPointerException

下面是我的代码-

 @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment, container, false);

    buttonLoginLogout = (Button) view.findViewById(R.id.buttonLoginLogout);
    textInstructionsOrLink = (TextView) view.findViewById(R.id.instructionsOrLink);

    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

    Session session = Session.getActiveSession();
    if (session == null) {
        if (savedInstanceState != null) {
        session = Session.restoreSession(getActivity(), null, statusCallback,
            savedInstanceState);
        }
        if (session == null) {
        session = new Session(getActivity());
        }
        Session.setActiveSession(session);
        if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
        session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
        }
    }

    updateView();

    return view;
    }

    @Override
    public void onStart() {
    super.onStart();
    Session.getActiveSession().addCallback(statusCallback);
    }

    @Override
    public void onStop() {
    super.onStop();
    Session.getActiveSession().removeCallback(statusCallback);
    }

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

    @Override
    public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    Session session = Session.getActiveSession();
    Session.saveSession(session, outState);
    }

    private void updateView() {
    Session session = Session.getActiveSession();
    if (session.isOpened()) {

        Intent thesisProject = new Intent(getActivity(), ThesisProjectAndroid.class);
        startActivity(thesisProject);

    } else {
        Log.d(TAG_LOGIN_FAILED,
            "There is something wrong with your Facebook account. Please try again.");

        textInstructionsOrLink.setText(R.string.instructions);
        buttonLoginLogout.setText(R.string.login);
        buttonLoginLogout.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickLogin();
        }
        });
    }
    }


    private void onClickLogin() {
    Session session = Session.getActiveSession();
    if (!session.isOpened() && !session.isClosed()) {
        session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
    } else {
        Session.openActiveSession(getActivity(), this, true, statusCallback);
    }
    }

    private void onClickLogout() {
    Session session = Session.getActiveSession();
    if (!session.isClosed()) {
        session.closeAndClearTokenInformation();
    }
    }

    private class SessionStatusCallback implements Session.StatusCallback {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        updateView();
    }
    }

我正在做的是 - 一旦我使用 Facebook 帐户登录,我就需要转到另一个 Intent(在模拟器中运行良好)但是一旦我在 android 手机中安装了这个应用程序,我总是在应用程序启动后立即获取 Login failed 甚至我都没有在 Facebook 登录页面上提供用户名和密码,而且我得到了上述异常.

What I am doing is- As soon as I am logged in using Facebook account, I need to go to another Intent (which is working fine in emulator) but as soon as I installed this application in the android phone, I always gets Login failed as soon as application is started without even I have provided the username and password on the facebook login page and also I get the above exception.

还有谁能让我知道我的逻辑在 updateView 方法 中是否正确 - 我想做的是,一旦 Facebook 身份验证正确意味着我可以登录,然后我需要去另一个 Intent.

And also can anyone let me know my logic is right in the updateView method or not- What I wanted to do is, as soon as Facebook authentication is correct means I am able to login, then I need to go to another Intent.

谁能帮我看看为什么会发生这种事情?

Can anyone help me out here why this things is happening?

推荐答案

感谢@Matt Accola.那个页面这样说:

Tank you @Matt Accola. that page say this:

当在 Android 系统设置中打开不保留活动"开发者选项时,Facebook SSO 登录过程会中断.LoginActivity 会被重复调用,并且每次都会泄露 LoginActivity 的一个实例.登录从未真正完成,最终需要终止该进程.

When the "Don't keep activities" developer option is turned on in the Android system settings the Facebook SSO login process is broken. The LoginActivity is called repeatedly and each time an instance of LoginActivity is leaked. The login never actually completes and the process eventually needs to be killed.

请注意,如果关闭不保留活动"设置,此错误将无法重现.

Please note this bug is not reproducible if the "Don't keep activities" settings is turned off.

请注意,只有当所有用户帐户都从原生 Facebook 应用程序注销时,此错误才会重现.

Please note this bug is only reproducible if all user accounts are logged out of the native Facebook app.

重现步骤:1. 在设备上的 Android 开发者选项(设置下)中启用不保留活动"设置.

Steps to Reproduce: 1. Enable "Don't keep activities" setting in Android Developer Options (under Settings) on device.

  1. 验证设备上是否安装了适用于 Android 的原生 Facebook 应用.

  1. Verify native Facebook app for Android is installed on device.

确保所有用户帐户都已从原生 Facebook 应用中注销.

Make sure all user accounts are logged out of the native Facebook app.

下载适用于 Android 的 Facebook SDK 源代码和示例,并将项目导入 Eclipse.

Download the Facebook SDK for Android source code and samples and import the projects into Eclipse.

启动 HelloFacebookSample.

Launch the HelloFacebookSample.

点击登录按钮.应显示 Facebook 登录屏幕.

Tap the Log In button. The Facebook login screen should be displayed.

输入 Facebook 凭据并点击登录按钮.等待后,可能会出现身份验证对话框.

Enter Facebook credentials and tap Log In button. After a wait the auth dialog may appear.

在身份验证对话框中点击确定".

Tap OK on the auth dialog.

预期行为:登录过程应完成,HelloFacebookSample 屏幕应显示为登录状态.

Expected Behavior: The login process should complete and the HelloFacebookSample screen should be displayed in the logged in state.

实际行为:Facebook 屏幕与进度对话框保持可见.整个系统变慢,最终进程开始崩溃,因为内存不足.我在此过程中捕获了堆转储,并且可以看到许多已泄露的 LoginActivity 实例.同时启用 StrictMode 将显示消息,指出 LoginActivity 实例正在泄漏.

Actual Behavior: The Facebook screen remains visible with the progress dialog. The entire system slows down and eventually processes start crashing as memory runs short. I have captured a heap dump during this process and can see numerous instances of LoginActivity which have been leaked. Also enabling StrictMode will show messages stating LoginActivity instances are being leaked.

这篇关于java.lang.RuntimeException:使用 Facebook 登录时无法传递结果 ResultInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆