Pushwoosh / pushwoosh-appcelerator-titanium

Other
33 stars 16 forks source link

Android - opening app from drawer loses the notification payload #41

Closed rborn closed 7 years ago

rborn commented 7 years ago

Hi, I have the next case I'm not sure how to handle:

PW_BROADCAST_PUSH set to true:

PW_BROADCAST_PUSH set to false:

So basically if the user opens the app from another place but the notification we somehow manage to lose the payload. Any way to handle this?

Thank you.

DimanAM commented 7 years ago

Latest Ti SDK started removing original intent extras from activity. So the information that activity was started from push notification got lost, leading to incorrent onPushOpen callback behaviour. It has been fixed in Pushwoosh SDK 3.0.1.

I could not reproduce the second case with notification disappearence. Notifications are atomatically canceled only if PW_BROADCAST_PUSH is set to true and push is received in foreground.

rborn commented 7 years ago

Thanks a lot, we're almost there :)

Now the app gets the payload correctly when opened from the drawer (but active in the background).

However it seems to lose the payload when the app is killed and it's opened from the notification (none of the events are called)

You can reproduce it like this:

04-24 14:28:34.230: D/StatusBar(23778): Clicked on content of 0|info.rborn.mst|1001|null|10076
04-24 14:28:34.238: D/IntentReceiver(23635): (main) [14385,21486] RECEIVE: 1493058508800
04-24 14:28:34.241: I/ActivityManager(779): START u0 {flg=0x10200000 cmp=info.rborn.mst/.MotorsportTotalComActivity (has extras)} from uid 10076 on display 0
04-24 14:28:34.246: W/V8Function(23635): Runtime disposed, cannot call function.
04-24 14:28:34.265: I/TiRootActivity(23635): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
04-24 14:28:34.265: I/TiApplication(23635): (main) [0,0] Analytics have been disabled

Also when this happens, and you put the app in background by hitting the phone's home button, the module doesn't detect the app went to background so it will behave like the app is in foreground and cancel the notification (events are triggered this time) .

You can reproduce it like this:

Thank you for your help 🤗

DimanAM commented 7 years ago
  • start the app
  • hit the phone's back button to close the app
  • send push
  • open the app from the notification
  • no event is triggered

Will fix that.

  • start the app
  • hit the phone's back button to close the app
  • send push
  • open the app from the notification
  • no event is triggered
  • hit phone's home button
  • send push
  • notification is canceled and events can be seen in log

Still can't reproduce. Are activity lifecycle callbacks completely broken after restart (i.e there are no ACTIVITY RESUMED, ACTIVITY PAUSED messages in the log)?

rborn commented 7 years ago

This is what I get when I hit home and then send push, like onPushOpened gets triggered for some reason:

04-24 17:47:54.750: I/ActivityManager(779): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher3/.Launcher (has extras)} from uid 1000 on display 0
04-24 17:47:54.758: E/EGL_emulation(792): tid 792: eglCreateSyncKHR(1215): error 0x3004 (EGL_BAD_ATTRIBUTE)
04-24 17:47:54.920: D/PushnotificationsModule(26030): (main) [7411,10381] Push: ACTIVITY PAUSED: 0
04-24 17:47:54.920: D/PushnotificationsModule(26030): (main) [0,10381] Push: unregistering receivers
04-24 17:47:54.928: D/PushnotificationsModule(26030): (main) [8,10389] Push: finished unregistering receivers
04-24 17:47:54.928: D/PushnotificationsModule(26030): (main) [0,10389] Push: ACTIVITY PAUSED: 0
04-24 17:47:54.928: D/PushnotificationsModule(26030): (main) [0,10389] Push: unregistering receivers
04-24 17:47:54.928: D/PushnotificationsModule(26030): (main) [0,10389] Push: finished unregistering receivers
04-24 17:47:54.928: D/PushnotificationsModule(26030): (main) [0,10389] Push: ACTIVITY SAVED INSTANCE
04-24 17:47:54.928: D/PushnotificationsModule(26030): (main) [0,10389] Push: ACTIVITY SAVED INSTANCE
04-24 17:47:54.928: D/PushnotificationsModule(26030): (main) [0,10389] Push: ACTIVITY STOPPED
04-24 17:47:54.928: D/PushnotificationsModule(26030): (main) [0,10389] Push: ACTIVITY STOPPED
04-24 17:47:54.961: E/Surface(26030): getSlotFromBufferLocked: unknown buffer: 0xdc5ccfb0
04-24 17:47:54.987: W/EGL_emulation(1163): eglSurfaceAttrib not implemented
04-24 17:47:54.987: W/OpenGLRenderer(1163): Failed to set EGL_SWAP_BEHAVIOR on surface 0xdf27ff40, error=EGL_SUCCESS
04-24 17:47:55.542: W/OpenGLRenderer(1163): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
04-24 17:47:55.542: W/OpenGLRenderer(1163): Incorrectly called buildLayer on View: ShortcutAndWidgetContainer, destroying layer...
04-24 17:48:12.130: I/Pushwoosh(26030): [com.pushwoosh.GCMListenerService] Received message: Bundle[{google.sent_time=1493122437594, pw_msg=1, p=z[, u={"newsid":"105244","ressort":"1"}, pri=, vib=0, title=a, google.message_id=0:1493122437603340%2895a49bf9fd7ecd}] from: 122494198821
04-24 17:48:12.131: I/Pushwoosh(26030): [AbsNotificationFactory] nofify: Bundle[{google.sent_time=1493122437594, onStart=true, pw_msg=1, p=z[, u={"newsid":"105244","ressort":"1"}, pri=, vib=0, title=a, google.message_id=0:1493122437603340%2895a49bf9fd7ecd, foreground=false}]
04-24 17:48:12.134: E/TiAPI(26030):  onPushReceived
04-24 17:48:12.134: E/TiAPI(26030):  {"message":"a","extras":{"ressort":"1","newsid":"105244"},"foreground":false,"data":{"u":"{\"newsid\":\"105244\",\"ressort\":\"1\"}","google.sent_time":1493122437594,"onStart":true,"title":"a","userdata":{"ressort":"1","newsid":"105244"},"p":"z[","foreground":false,"pri":"","vib":"0","pw_msg":"1","google.message_id":"0:1493122437603340%2895a49bf9fd7ecd"}}
04-24 17:48:12.141: D/Pushwoosh(26030): [RequestManager] Try To send: messageDeliveryEvent
04-24 17:48:12.144: D/PushnotificationsModule(26030): (main) [17216,27605] Push: message received
04-24 17:48:12.144: E/TiAPI(26030):  onPushOpened
04-24 17:48:12.144: E/TiAPI(26030):  {"message":"a","extras":{"ressort":"1","newsid":"105244"},"foreground":false,"data":{"u":"{\"newsid\":\"105244\",\"ressort\":\"1\"}","google.sent_time":1493122437594,"onStart":true,"title":"a","userdata":{"ressort":"1","newsid":"105244"},"p":"z[","foreground":false,"message_id":1001,"pri":"","vib":"0","pw_msg":"1","google.message_id":"0:1493122437603340%2895a49bf9fd7ecd"}}
04-24 17:48:12.147: V/FFmpegExtractor(451): SniffFFMPEG
DimanAM commented 7 years ago

However it seems to lose the payload when the app is killed and it's opened from the notification (none of the events are called)

Fixed in 3.1.0

I have completely changed foreground push handling logic. But I am still not sure what could cause weird behaviour with notification cancelling in background. Please check updated version.

rborn commented 7 years ago

On it, I'll let you know asap. Thank you very much 👍

rborn commented 7 years ago

Ok, so this version seems to work better, but I still get this

Could be this? https://jira.appcelerator.org/browse/TIMOB-24497

The foreground/background issues seems to be fixed or at least I didn't find them for now Thank you.

rborn commented 7 years ago

Damn, the new fg/bg stuff you did breaks my app - I have a custom module built to allow the app to be brought from background from an url in a browser

Let me investigate this a little. Sorry for the mess.

rborn commented 7 years ago

Ok, so nothing to do with the other module :( That is just to handle correctly a browsable intent not to start a new instance of the app.

Sadly I can't use the 3.1.0 version as it breaks the browsable part 😢 Only if it would be possible to fix the back button for 3.0.1 it would be good enough for me right now

rborn commented 7 years ago

With 3.1.0 the app intent gets the extras from pushwoosh (when opened from notification and closed with the back button), I can do this:

var rootIntent = Ti.App.Android.launchIntent;
console.error(rootIntent.getStringExtra('PUSH_RECEIVE_EVENT'));

So if you could send this extras to the app in 3.0.1 I think I could manage from there.🙏

DimanAM commented 7 years ago

Ok, so this version seems to work better, but I still get this

  • start the app
  • hit the phone's back button to close the app
  • send push
  • open the app from the notification
  • no event is triggered

In this scenario original Activity intent extras are getting lost. As workaround module saves push payload and provides it later in onPushOpened callback when pushwoosh.initilize() is invoked. Please check pushwoosh module is getting initialized after opening application from push notification.

Damn, the new fg/bg stuff you did breaks my app - I have a custom module built to allow the app to be brought from background from an url in a browser

Ok, so nothing to do with the other module :( That is just to handle correctly a browsable intent not to start a new instance of the app.

Sadly I can't use the 3.1.0 version as it breaks the browsable part 😢 Only if it would be possible to fix the back button for 3.0.1 it would be good enough for me right now

This is strange. Pushwoosh module cannot affect application deep linking. And the recent changes were only connected with Activity lifecycle callbacks.

rborn commented 7 years ago

This is strange. Pushwoosh module cannot affect application deep linking. And the recent changes were only connected with Activity lifecycle callbacks.

The module I have makes the app to return at the current stage when called from a webpage (because Titanium's activity lifecycle is really broken), but as soon as I install 3.1.0 the app restarts and then the next activities don't open anymore. This doesn't happen with 3.0.1

Would it be possible to make the trick with saving the payload but for 3.0.1 ?

Thank you.

rborn commented 7 years ago

@DimanAM let me dig into this a little more please, I just want to be sure it's not my module doing weird stuff. Sorry for stressing you :)

rborn commented 7 years ago

@DimanAM I think we found the issue, Ti 6 changed some stuff on how the main activity gets handled and my module behaved weird on android 4. We fixed that and all seems to be ok now. I'll close this, thank you for your help 🤗