Android How to - Start an Activity from another Activity








Question

We would like to know how to start an Activity from another Activity.

Answer

// ww w  .ja  v a 2s  .co m
import android.app.Activity;
import android.content.Intent;
import android.os.Handler;

public class Main {
  public static void startNewActivity(final Activity from, final Class<?> to, long delayMillis, final boolean finishSelf){
    
    Handler handler = new Handler();
    Runnable r = new Runnable(){
      @Override
      public void run() {
        Intent intent = new Intent(from, to);
        from.startActivity(intent);
        if(finishSelf == true)
          from.finish();
      }
    };
    handler.postDelayed(r, delayMillis);
  }
}