'Android: Redirect to another Activity after delay

So I am developing a simple app for a college project, And I have been able to integrate a Facebook login using fragments.

But I now am stuck trying to redirect the user after they login. I simply want to redirect them to the second activity page

Here is my code for the Facebook login success

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

        }

} 


Solution 1:[1]

Simply call a new activity through intent:

Intent i = new Intent(LoginActivity.this, HomeActivity.class);
startActivity(i);
finish();

Solution 2:[2]

Check this:-

new Handler().postDelayed(new Runnable() {
                  @Override
                  public void run() {

                      Intent i=new Intent(CurrentActivity.this,Next.class);
                      startActivity(i);
                  }
              }, 3000);

Solution 3:[3]

A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue.

You can use Handler postDelayed Method easily .

Handler hd = new Handler();
            hd.postDelayed(new Runnable() {
                @Override
                public void run() {

               // Add Your Intent

             }

            }, 2000); // Time Delay ,2 Seconds 
     }

Solution 4:[4]

In Kotlin;

  val r = Runnable {

        startActivity(Intent(this, AuthorActivity::class.java))
    }
    val h = Handler()

    h.postDelayed(r, 10) 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mansha Chuttani
Solution 2 Chandan
Solution 3 IntelliJ Amiya
Solution 4 Murat Çak?r