簡體   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