java.lang.RuntimeException: Failure delivering result ResultInfo while logging using Facebook

流过昼夜 提交于 2020-01-12 19:08:15

问题


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

Below is my code-

 @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();
    }
    }

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.

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?


回答1:


Tank you @Matt Accola. that page say this:

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.

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

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

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

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

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

  4. Launch the HelloFacebookSample.

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

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

  7. Tap OK on the auth dialog.

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

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.



来源:https://stackoverflow.com/questions/14611969/java-lang-runtimeexception-failure-delivering-result-resultinfo-while-logging-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!