Activity:
public class FrameActivity extends BaseActivity { public static CallbackManager callbackManager; @Override protected void onCreate(Bundle savedInstanceState) { // FacebookSdk.sdkInitialize is called in the Application onCreate callbackManager = CallbackManager.Factory.create(); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode, resultCode, data); } } Fragment:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_login, container, false); LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button); loginButton.setReadPermissions("user_friends"); loginButton.setReadPermissions("public_profile"); loginButton.setReadPermissions("email"); loginButton.setReadPermissions("user_birthday"); // If using in a fragment loginButton.setFragment(this); // Other app specific specialization // Callback registration loginButton.registerCallback(FrameActivity.callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { } @Override public void onCancel() { // App code } @Override public void onError(FacebookException exception) { // App code } }); return view; }
Try this:
Init FacebookSdk.sdkInitialize() in fragment's onCreateView().
Next line init callbackManager = CallbackManager.Factory.create();
Implement on onActivityResult() in Fragment class.
Add your callbackManager.onActivityResult(requestCode, resultCode, data); in fragment onActivityResult().
Make sure remove FacebookInit() and callbackManager from activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With