Created
July 11, 2016 11:44
-
-
Save mmichler/4d3b782826b582733739d277b2b1b5a7 to your computer and use it in GitHub Desktop.
Android Activity in single task launchmode with Intent handling code
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
public class SingleTaskActivity extends AppCompatActivity { | |
private boolean mIntentConsumed; | |
@Override | |
public void onResume() { | |
super.onResume(); | |
processIntent(); | |
} | |
@Override | |
protected void onNewIntent(Intent intent) { | |
super.onNewIntent(intent); | |
setIntent(intent); | |
mIntentConsumed = false; | |
} | |
private void processIntent() { | |
Intent intent = getIntent(); | |
String action = intent.getAction(); | |
String type = intent.getType(); | |
boolean launchedFromHistory = | |
(intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0; | |
if (launchedFromHistory || mIntentConsumed) { | |
return; | |
} | |
// Intent handling code goes here | |
mIntentConsumed = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment