Created
October 3, 2018 01:27
-
-
Save alejandro-rios/f6de9e2a1d58f0e5cacf6b1de2b9b489 to your computer and use it in GitHub Desktop.
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
// MainActivity.java | |
private void onSomeItemSelected(Item item) { | |
Intent intent = new Intent(this, SomeAwesomeAndHyperRealisticDetailActivity.class); | |
intent.putExtra(SomeAwesomeAndHyperRealisticDetailActivity.EXTRA_ITEM_ID, "id"); | |
intent.putExtra(SomeAwesomeAndHyperRealisticDetailActivity.EXTRA_WANNA_SHOW, true); | |
startActivity(intent); | |
} | |
// SomeAwesomeAndHyperRealisticDetailActivity.java | |
public static String EXTRA_ITEM_ID = "EXTRA_ITEM_ID"; | |
public static boolean EXTRA_WANNA_SHOW = "EXTRA_WANNA_SHOW"; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
.... | |
Bundle bundle = getIntent().getExtras(); | |
if (bundle != null) { | |
String id = bundle.getString(EXTRA_ITEM_ID); | |
if (id == null) { | |
throw new IllegalStateException(); | |
} else { | |
boolean wannaShow = bundle.getBoolean(EXTRA_WANNA_SHOW, false); | |
loadData(id); | |
} | |
} else { | |
throw new IllegalStateException(); | |
} | |
.... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment