Write a HashMap to a Parcel, class of key and value are both String - Android android.os

Android examples for android.os:Parcel

Description

Write a HashMap to a Parcel, class of key and value are both String

Demo Code


//package com.java2s;

import java.util.Map;
import java.util.Map.Entry;
import android.os.Parcel;

public class Main {
    /**/*  www .  ja  v a  2  s  .c  om*/
     * Write a HashMap to a Parcel, class of key and value are both String
     *
     * @param map
     * @param out
     * @param flags
     */
    public static void writeHashMapStringAndString(Map<String, String> map,
            Parcel out, int flags) {
        if (map != null) {
            out.writeInt(map.size());
            for (Entry<String, String> entry : map.entrySet()) {
                out.writeString(entry.getKey());
                out.writeString(entry.getValue());
            }
        } else {
            out.writeInt(-1);
        }
    }
}

Related Tutorials