Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fcaldarelli/32b2859be0ef186a90be74ef197d9b52 to your computer and use it in GitHub Desktop.
Save fcaldarelli/32b2859be0ef186a90be74ef197d9b52 to your computer and use it in GitHub Desktop.
Onesignal: Resume last Activity when opening a Notification
// 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