Android:延迟后重定向到另一个Activity

Cla*_*r93 5 java redirect android facebook

所以我正在为一个大学项目开发​​一个简单的应用程序,我已经能够使用片段集成Facebook登录.

但是我现在在登录后试图重定向用户.我只是想将它们重定向到第二个活动页面

这是我登录Facebook登录成功的代码

private FacebookCallback<LoginResult> mCallback=new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {
        AccessToken accessToken = loginResult.getAccessToken();
        Profile profile = Profile.getCurrentProfile();
        if (profile != null) {
            display.setText("Welcome: " + profile.getFirstName());
            //Redirect to Second Activity

        }

} 
Run Code Online (Sandbox Code Playgroud)

Sha*_*dge 5

要进行延迟转换,请使用Handler类的postDelayed(Runnable r, long delayMillis)方法,例如:

   Runnable r = new Runnable() {

            @Override
            public void run() {
                // if you are redirecting from a fragment then use getActivity() as the context.
                startActivity(new Intent(CurrentActivity.this, TargetActivity.class));

            }
        };


        Handler h = new Handler();
        // The Runnable will be executed after the given delay time
        h.postDelayed(r, 1500); // will be delayed for 1.5 seconds
Run Code Online (Sandbox Code Playgroud)