我正在尝试使用自定义界面登录Facebook,它在Activity类中运行良好.我也必须在Fragment做同样的事情.但回调没有执行.是不是可以在Fragment的OnActivityResult中添加CallbackResult?
您只需在Activity onActivityResult中添加此代码即可.
for (Fragment fragment : getSupportFragmentManager().getFragments()) { //System.out.println("@#@"); fragment.onActivityResult(requestCode, resultCode, data); }
然后你的片段onActivityResult肯定会起作用.
@Override public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { callbackManager.onActivityResult(requestCode, resultCode, data); }
是的,可以在片段中实现facebook登录,你唯一需要做的就是在你的主机活动中调用OnActivityResult,如下所示:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Fragment fragment = getFragmentManager().findFragmentById(R.id.your_host_fragment_in_activity); fragment.onActivityResult(requestCode, resultCode, data); }
然后在yout片段中再次调用onActivityResult.