start Activity By Class and Bundle - Android android.app

Android examples for android.app:Activity Start

Description

start Activity By Class and Bundle

Demo Code

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

public class Main {

  public static Boolean startActivityByClass(Context context, String packName, String className, Bundle bundle) {
    Intent mIntent = new Intent();
    mIntent.setClassName(packName, className);
    if (bundle != null) {
      mIntent.putExtras(bundle);//from  w  w w.j  a va  2 s  . c om
    }
    try {
      context.startActivity(mIntent);
      return true;
    } catch (Exception wException) {
      return false;
    }
  }

  public static Boolean startActivityByClass(Context context, String className) {
    return startActivityByClass(context, context.getPackageName(), className, null);
  }

}

Related Tutorials