Skip to content

Instantly share code, notes, and snippets.

@mmichler
Created July 11, 2016 11:44
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 mmichler/4d3b782826b582733739d277b2b1b5a7 to your computer and use it in GitHub Desktop.
Save mmichler/4d3b782826b582733739d277b2b1b5a7 to your computer and use it in GitHub Desktop.
Android Activity in single task launchmode with Intent handling code
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