Android How to - Start Activity with Bundle








Question

We would like to know how to start Activity with Bundle.

Answer

//from  w w  w . j av a 2 s .co m
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

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