start New Activity via android.os.Handler - Android android.app

Android examples for android.app:Activity Start

Description

start New Activity via android.os.Handler

Demo Code

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//w  ww .j a va2 s.c  o  m
      public void run() {
        Intent intent = new Intent(from, to);
        from.startActivity(intent);
        if (finishSelf == true)
          from.finish();
      }
    };
    handler.postDelayed(r, delayMillis);
  }

}

Related Tutorials