Use Intent To Load Activity passing key and value - Android android.app

Android examples for android.app:Activity Start

Description

Use Intent To Load Activity passing key and value

Demo Code

import android.content.Context;
import android.content.Intent;

public class Main {

  public static void IntentToActivity(Context context, Class clazz, String[] key, String[] value) {
    if (clazz == null)
      return;//from w w w. j a v a2  s. c  o m
    Intent intent = new Intent();
    for (int i = 0; i < key.length; i++) {
      intent.putExtra(key[i], value[i]);
    }
    intent.setClass(context, clazz);
    context.startActivity(intent);
  }

  public static void IntentToActivity(Context context, String className, String[] key, String[] value) {
    Class clazz = getClass(className);
    IntentToActivity(context, clazz, key, value);
  }

  public static Class getClass(String classname) {
    Class res = null;
    try {
      res = Class.forName(classname);
    } catch (ClassNotFoundException e) {

    }
    return res;
  }

}

Related Tutorials