Search code examples
androidfacebookfacebook-graph-apiandroid-fragmentsfacebook-login

Facebook login in fragment in android


I'm trying to login Facebook using custom interface it worked fine in Activity class. same thing i have to do in Fragment too. but Callback is not executing. is it not possible to add CallbackResult in Fragment's OnActivityResult ??


Solution

  • Yes it's Posssible to implement facebook login in fragment, the only thing you need to do is call OnActivityResult in your host activity like this:

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

    and then call onActivityResult again in yout fragment.