Created
July 6, 2018 16:20
-
-
Save fcaldarelli/32b2859be0ef186a90be74ef197d9b52 to your computer and use it in GitHub Desktop.
Onesignal: Resume last Activity when opening a Notification
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
// Add the following code to the top of onCreate in your launcher Activity. | |
// --- | |
// By default OneSignal calls startActivity with the following intent flags: | |
// Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK | |
private static boolean activityStarted; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
if ( activityStarted | |
&& getIntent() != null | |
&& (getIntent().getFlags() & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) { | |
finish(); | |
return; | |
} | |
activityStarted = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment