start Activity by Class<?> - Android android.app

Android examples for android.app:Activity Start

Description

start Activity by Class<?>

Demo Code

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

public class Main {

  public static Bundle bundle;
  public static Class className;

  public static void startActivity(Context context, Class cls) {

    Intent intent = new Intent();
    intent.setClass(context, cls);// w w  w. j a va 2  s. co  m
    context.startActivity(intent);

  }

  public static void startActivity(Context context, Class cls, Bundle bundle) {

    Intent intent = new Intent();
    intent.setClass(context, cls);
    intent.putExtras(bundle);
    context.startActivity(intent);
  }

}

Related Tutorials