如何在android中覆盖onactivityResult

时间:2014-04-26 19:11:12

标签: android facebook override onactivityresult

我从facebook文档here

获取此代码
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
       // @Override
        public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
            Log.e("Activity", String.format("Error: %s", error.toString()));
        }

        @Override
        public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
            Log.i("Activity", "Success!");
        }
    });
}

并将其放在MainActivity中,但eclipse会出错:The method onComplete(FacebookDialog.PendingCall, Bundle) of type new FacebookDialog.Callback(){} must override or implement a supertype methodThe method onComplete(FacebookDialog.PendingCall, Bundle) of type new FacebookDialog.Callback(){} must override or implement a supertype method等,为什么?

1 个答案:

答案 0 :(得分:0)

按照教程指出你需要遵循Prerequisits部分。您必须实施所有Facebook登录教程才能继续共享。

我所指出的特定方法的代码与您的相似:

    public void onActivityResult(int requestCode, int resultCode, Intent data){
    Session.getActiveSession().onActivityResult(activity, requestCode, resultCode, data);

    uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback(){
        public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data){
            Log.e(activity.getClass().getName(), String.format("Error %s", error.toString()));
        }

        public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data){
            Log.i(activity.getClass().getName(), "Success!!!");

        }
    });
}

我看到的方法的唯一区别是我不会调用super,并且使用Session.getActiveSession()...来自我提到的Facebook登录教程。

请检查您是否拥有最新的facebook sdk。我正在使用3.8版本。