Skip to content

Instantly share code, notes, and snippets.

@dadamssg
Created June 18, 2013 13:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadamssg/5805533 to your computer and use it in GitHub Desktop.
Save dadamssg/5805533 to your computer and use it in GitHub Desktop.
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