Created
June 18, 2013 13:52
-
-
Save dadamssg/5805533 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Parcel; | |
import android.os.Parcelable; | |
import java.util.HashMap; | |
import java.util.Map; | |
public class ActivityParms implements Parcelable { | |
private Map<String, Object> parms; | |
public ActivityParms() { | |
parms = new HashMap<String, Object>(); | |
} | |
private ActivityParms(Parcel in) { | |
parms = new HashMap<String, Object>(); | |
readFromParcel(in); | |
} | |
public void writeToParcel(Parcel dest, int flags) { | |
dest.writeInt(parms.size()); | |
for (String s : parms.keySet()) { | |
dest.writeString(s); | |
dest.writeValue(parms.get(s)); | |
} | |
} | |
public void readFromParcel(Parcel in) { | |
int count = in.readInt(); | |
for (int i = 0; i < count; i++) { | |
parms.put(in.readString(), in.readValue(Object.class.getClassLoader())); | |
} | |
} | |
public ActivityParms put(String key, Object value) { | |
parms.put(key, value); | |
return this; | |
} | |
public <T> T get(String key) { | |
return parms.get(key) == null ? null : (T) parms.get(key); | |
} | |
public int describeContents() { | |
return 0; | |
} | |
public static final Parcelable.Creator<ActivityParms> CREATOR = new Parcelable.Creator<ActivityParms>() { | |
public ActivityParms createFromParcel(Parcel in) { | |
return new ActivityParms(in); | |
} | |
public ActivityParms[] newArray(int size) { | |
return new ActivityParms[size]; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment