Created
October 9, 2014 03:03
-
-
Save r0adkll/6ac8dec56cfe42de6e4e to your computer and use it in GitHub Desktop.
isWrongInstance() for Android Main Activities
This file contains hidden or 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
/** | |
* 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