Skip to content

Instantly share code, notes, and snippets.

@yccheok
Created February 6, 2024 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yccheok/a6c14ae0b759554e2e161d4a44ec9c56 to your computer and use it in GitHub Desktop.
Save yccheok/a6c14ae0b759554e2e161d4a44ec9c56 to your computer and use it in GitHub Desktop.
public static <E extends Enum<E>> void putExtra(
@NonNull Intent intent,
@NonNull String key,
@NonNull E enumValue) {
intent.putExtra(
key,
enumValue.name()
);
}
public static <E extends Enum<E>> E readFrom(
@NonNull Bundle bundle,
@NonNull String key,
@NonNull Class<E> enumType) {
final String name = bundle.getString(key);
return Enum.valueOf(enumType, name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment