Last active
September 15, 2015 08:11
-
-
Save Krumelur/51c621e1e7ce4843600e to your computer and use it in GitHub Desktop.
Android Extras Bundle Extensions for AND102 to prevent magic strings
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
// Put | |
intent.PutExtra(EXTRAS.ItemPosition, position); | |
// Get | |
int position = this.Intent.GetExtra(EXTRAS.ItemPosition, -1); |
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
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