Skip to content

Instantly share code, notes, and snippets.

@rivancic
Last active December 21, 2015 13:06
Show Gist options
  • Save rivancic/35a36ce43feb0bb713b2 to your computer and use it in GitHub Desktop.
Save rivancic/35a36ce43feb0bb713b2 to your computer and use it in GitHub Desktop.
Android Activity Factory metnod for passing in arguments
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