Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import java.io.Serializable;
import java.util.Map;

public class Main {

    public static Intent mapToIntent(Context context, Class<?> clazz, Map<String, Object> map) {
        Intent intent = new Intent(context, clazz);
        Bundle bundle = new Bundle();
        if (map != null && map.size() > 0) {
            for (String key : map.keySet()) {
                if (map.get(key) instanceof String) {
                    bundle.putString(key, (String) map.get(key));
                } else if (map.get(key) instanceof Integer) {
                    bundle.putInt(key, (Integer) map.get(key));
                } else if (map.get(key) instanceof Boolean) {
                    bundle.putBoolean(key, (Boolean) map.get(key));
                } else if (map.get(key) instanceof Double) {
                    bundle.putDouble(key, (Double) map.get(key));
                } else if (map.get(key) instanceof Long) {
                    bundle.putLong(key, (Long) map.get(key));
                } else if (map.get(key) instanceof Float) {
                    bundle.putFloat(key, (Float) map.get(key));
                } else if (map.get(key) instanceof Double) {
                    bundle.putDouble(key, (Double) map.get(key));
                } else if (map.get(key) instanceof Serializable) {
                    bundle.putSerializable(key, (Serializable) map.get(key));
                } else if (map.get(key) instanceof Parcelable) {
                    bundle.putParcelable(key, (Parcelable) map.get(key));
                }
            }
        }
        return intent.putExtras(bundle);
    }
}