Last active
December 21, 2015 13:06
-
-
Save rivancic/35a36ce43feb0bb713b2 to your computer and use it in GitHub Desktop.
Android Activity Factory metnod for passing in arguments
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 static final String ARGUMENT_ARG = "ARGUMENT_ARG"; | |
private String argumentValue; | |
public class ArgumentActivity extends Activity { | |
/** | |
* Factory method for passing arguments. | |
*/ | |
public static Intent getIntent(String argumentValue) { | |
Intent intent = new Intent(context, ArgumentActivity.class); | |
intent.putExtra(ARGUMENT_ARG, argumentValue); | |
return intent; | |
} | |
/** | |
* Parsing arguments. | |
*/ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
Bundle extras = getIntent().getExtras(); | |
if(extras.containsKey(ARGUMENT_ARG)) { | |
argumentValue = extras.getString(ARGUMENT_ARG); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment