facebook退出时出错

时间:2015-02-05 04:41:24

标签: android facebook logout

我使用以下代码从我的应用程序中的fb注销。这段代码给出了注销错误,我无法弄清楚问题,任何帮助都将不胜感激。

错误消息是

AsyncFacebookRunner类型中的方法注销(Context,AsyncFacebookRunner.RequestListener)不适用于参数(ProfileFragment,new AsyncFacebookRunner.RequestListener(){})

 final RelativeLayout relativeLayout3 = (RelativeLayout) rootView
                .findViewById(R.id.logoutlistview);
        relativeLayout3.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                logoutFromFacebook();
        });

        return rootView;
    }

    public void logoutFromFacebook() {
        AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(facebook);
        asyncRunner.logout(getActivity(), new RequestListener() {
            @Override
            public void onComplete(String response, Object state) {
                Log.d("Logout from Facebook", response);
                if (Boolean.parseBoolean(response) == true) {
                    Intent intent = new Intent(getActivity(),
                             LandingActivity.class);
                             startActivity(intent);
                             intent.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK
                             | Intent.FLAG_ACTIVITY_NEW_TASK);
                             startActivity(intent);
                             getActivity().overridePendingTransition(R.anim.slide_in_right,
                             R.anim.slide_out_left);
                }
            }

            @Override
            public void onFileNotFoundException(FileNotFoundException e,
                    Object state) {
            }

            @Override
            public void onIOException(IOException e, Object state) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onMalformedURLException(MalformedURLException e,
                    Object state) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onFacebookError(FacebookError e, Object state) {
                // TODO Auto-generated method stub

            }
        });

    }

在我的logcat中输出

enter image description here

如果有更好的方法从系统退出,请提出建议

2 个答案:

答案 0 :(得分:2)

Fragment

中试试
  asyncRunner.logout(getActivity(), new RequestListener() { 

您应该将上下文作为asyncRunner.logout(....)

中的第一个参数传递

答案 1 :(得分:0)

使用以下内容:

public static void facebookLogout(Context context) {
        Session session = Session.getActiveSession();
        if (session != null) {

            if (!session.isClosed()) {
                session.closeAndClearTokenInformation();
            }
        } else {

            session = new Session(context);
            Session.setActiveSession(session);

            session.closeAndClearTokenInformation();
        }

    }