Skip to content

Instantly share code, notes, and snippets.

@r0adkll
Created October 9, 2014 03:03
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 r0adkll/6ac8dec56cfe42de6e4e to your computer and use it in GitHub Desktop.
Save r0adkll/6ac8dec56cfe42de6e4e to your computer and use it in GitHub Desktop.
isWrongInstance() for Android Main Activities
/**
* Dev tools and the play store (and others?) launch with a different intent, and so
* lead to a redundant instance of this activity being spawned. <a
* href="http://stackoverflow.com/questions/17702202/find-out-whether-the-current-activity-will-be-task-root-eventually-after-pendin"
* >Details</a>.
*/
private boolean isWrongInstance() {
if (!isTaskRoot()) {
Intent intent = getIntent();
boolean isMainAction = intent.getAction() != null && intent.getAction().equals(ACTION_MAIN);
return intent.hasCategory(CATEGORY_LAUNCHER) && isMainAction;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment