Skip to content

Instantly share code, notes, and snippets.

@amatkivskiy
Created September 22, 2016 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amatkivskiy/1bb5e05fcf08eb5c2cc80f2bab08b6e9 to your computer and use it in GitHub Desktop.
Save amatkivskiy/1bb5e05fcf08eb5c2cc80f2bab08b6e9 to your computer and use it in GitHub Desktop.
// Check whether back stack exists.
if (Referrers.hasReferrer(getIntent())) {
// If the current back stack exists just navigate to parent activity.
Class parentActivityClass = Referrers.getReferrer(getIntent());
Intent intent = new Intent(this, parentActivityClass).setFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
this.startActivity(intent);
} else {
// If ItemDetailsActivity was open for example from the notification then create back stack manually.
Intent collectionsIntent = ContentCollectionActivity.createIntent(this, null);
Intent mainActivityIntent = new Intent(this, MainActivity.class);
TaskStackBuilder.create(this)
.addNextIntent(mainActivityIntent)
.addNextIntent(collectionsIntent)
.startActivities();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment