Go to Activity by parameter - Android Activity

Android examples for Activity:Activity Start

Description

Go to Activity by parameter

Demo Code

import java.util.Map;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;

public class Main {

  public static void toActivity(Context context, Class<?> class1,
      Map<String, String> param) {
    Intent it = new Intent(context, class1);
    if (it != null) {
      if (param != null && !param.isEmpty()) {
        for (String key : param.keySet()) {
          it.putExtra(key, param.get(key));
        }/* ww w  .  j  a  va2s  .  c o  m*/
      }
      try {
        ((Activity) context).startActivityForResult(it, 0);
      } catch (ActivityNotFoundException e) {
        throw new RuntimeException(e);
      }
    }
  }
}

Related Tutorials