繁体   English   中英

成功登录Facebook后如何启动新活动?

[英]How start new activity after successful Facebook login?

我正在进行Facebook登录。 在我的主要XML中,我只有Facebook登录按钮。

我想在Facebook成功登录后开始新页面,但是在Facebook成功登录后,它不显示我的新XML页面(欢迎使用XML布局)。 而是显示空白页面。

我怎样才能解决这个问题?

GitHub链接

我的片段:

    public static class PlaceholderFragment extends Fragment {

        private CallbackManager callbackManager;
        private FacebookCallback<LoginResult>callback=new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {

                //Is there problem here?
                AccessToken accessToken=loginResult.getAccessToken();
                Profile profile=Profile.getCurrentProfile();
                Intent intent = new Intent(getActivity().getApplicationContext(), com.berkkarabacak.scarce.Profile.class);
                startActivity(intent);
                //Is there problem here?


            }

            @Override
            public void onCancel() {

            }

            @Override
            public void onError(FacebookException e) {
            }
        };


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
            callbackManager=CallbackManager.Factory.create();

        }

        @Override


        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            LoginButton loginButton=(LoginButton) rootView.findViewById(R.id.login_button);
            loginButton.setReadPermissions("user_friends");
            loginButton.setFragment(this);
            loginButton.registerCallback(callbackManager,callback);
            return rootView;
            }

        @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            callbackManager.onActivityResult(requestCode,resultCode,data);
        }
    }
}

使用活动上下文

 Intent intent = new Intent(getActivity(), com.berkkarabacak.scarce.Profile.class);

请尝试这个;

        Fragment fragment = new sendFragment();
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.content, fragment);
        fragmentTransaction.commit();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM