Skip to content

Instantly share code, notes, and snippets.

@Krumelur
Last active September 15, 2015 08:11
Show Gist options
  • Save Krumelur/51c621e1e7ce4843600e to your computer and use it in GitHub Desktop.
Save Krumelur/51c621e1e7ce4843600e to your computer and use it in GitHub Desktop.
Android Extras Bundle Extensions for AND102 to prevent magic strings
// Put
intent.PutExtra(EXTRAS.ItemPosition, position);
// Get
int position = this.Intent.GetExtra(EXTRAS.ItemPosition, -1);
public enum EXTRAS
{
ItemPosition
}
public static class ExtrasExtensions
{
public static void PutExtra(this Intent intent, EXTRAS extra, int value)
{
intent.PutExtra(extra.ToString(), value);
}
public static int GetExtra(this Intent intent, EXTRAS extra, int defaultValue)
{
if(intent == null)
{
return defaultValue;
}
return intent.GetIntExtra(extra.ToString(), defaultValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment