0

My Android app has a notification open handler (using OneSignal push notifications) and what it does is, when a push notification is received and the user taps on it, the app comes to foreground and opens an activity with the details of a product.

This works perfectly fine when the app is in background or foreground, but the problem arrises when the app is closed: the push notification arrives, the user taps on it, the app starts but goes directly to the product detail. It seems that the MainActivity, where the product list is shown, is not loading... Then, when I click the back button, the app dismisses, like it doesn't have history to go back...

The code I'm using in the push notification callback is:

Intent intentProduct = new Intent(getApplicationContext(), ProductDetailActivity.class);
                        intentProduct.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
                        ItemParcel pProduct = new ItemParcel();
                        pProduct.setId(id);
                        intentProduct.putExtra("ItemParcel", pProduct);
                        startActivity(intentProduct);

It seems that some of these flags on the intent is not doing the right thing, but this exactly what is on the OneSignal docs.

Another this I added to the manifest (according to Onesignal docs) is:

<meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />

Any ideias on how to fix this?

fana
  • 374
  • 7
  • 17
  • But the intent you provded is supposed to go directly to Product detail page with provided id. To go to main activity you should use MainActivity.class when initializing intent. – shtolik Nov 19 '16 at 12:33
  • But shouldn't it open MainActivity first? Maybe I should open MainActivity first and set some variable and then is that variable is set, go to the detail of the product... – fana Nov 19 '16 at 12:36
  • Android open the activity which class is given in the Intent. It may know nothing about other activities at that point and doesn't care. You tell which one to open. – shtolik Nov 19 '16 at 12:40
  • Yep, I actually solved this by checking if MainActivity is not null and go directly to the product detail. If it's null then I start it up and set some variables that I check on MainActivity onCreate and pull the product detail from there. Thanks! – fana Nov 19 '16 at 16:55
  • @fana can u explain a litle more im havin the same issue here [link](https://stackoverflow.com/questions/49573533/onesignal-cant-open-app-closed-when-click-notification-android?noredirect=1#comment86154563_49573533) – Kevin Dias Mar 30 '18 at 12:02

0 Answers0