Skip to content

Instantly share code, notes, and snippets.

@truongngoclinh
Last active April 7, 2017 05:09
Show Gist options
  • Save truongngoclinh/1246d76ec3803f9f72f6b279ab7c4265 to your computer and use it in GitHub Desktop.
Save truongngoclinh/1246d76ec3803f9f72f6b279ab7c4265 to your computer and use it in GitHub Desktop.
Passing list object through intent with gson.toJson and gson.fromJson
// passing to intent:
b.putSerializable(BUNDLE_PARAMS, new Gson().toJson(params));
// retrieving data:
List<KeyValueStringPair> params = new Gson().fromJson(b.getString(BUNDLE_PARAMS), new TypeToken<List<KeyValueStringPair>>(){}.getType())
// model class
public static class KeyValueStringPair implements Serializable {
@SerializedName("_key")
public String key;
@SerializedName("_value")
public String value;
public KeyValueStringPair() {
// compulsory empty constructor
}
public KeyValueStringPair(String key, String value) {
this.key = key;
this.value = value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment