react-native-push-notification
react-native-push-notification copied to clipboard
`onNotification` listener starting 'too late' on a killed Android app?
Hi, i hope you can give me a hint. I am sending silent pushes to the device and then display a local notification from within onNotification. Everything works fine except one scenario:
When i kill the app on Android and then send a silent notification to the device, the app is started in the background but onNotification is then not called for that first notification that starts the app. For all notifications after that onNotification gets called. To me it seemed that handleRemotePushNotification (in Java) is called too early for the onNotification listener to be ready, so i tested that by simply delaying handleRemotePushNotification for some seconds and that did the trick. I then get the onNotification event correctly also for the notification triggering the first start in the background.
The onRegister event works fine on first background start even without delaying the native code, only the onNotification listener seems to be 'late' when the app is started in background by a silent remote notification.
Might that be an issue/bug or am i doing something wrong in initializing the app or in the app lifecycle so that .configure is not ready with attaching all listeners when jsDelivery.notifyNotification is getting called?
I am calling .configure as the first thing directly from the index.js with popInitialNotification: true and requestPermissions: true.
react-native: 0.63.4 Library version: 7.0.0 Android Version: 9
Thanks a lot.
I think the issue was that i called .configure the index.js but still waited for a promise (data from async storage) to resolve before calling it. So i guess configure does not only have to be called in the index.js it also needs to be called synchronously, is that correct?
Is it possible in any way to wait for async data (like from async storage) and then run configure without risking to break the silent backend push scenarios? For my case a 'delay' option for notifications that need to start the app in background would have helped a lot i guess. Might that be something to think about?
Hi,
You can use lazy loading of your data. Only read them once you need it.
In this case, you read you data inside the App component and onNotification, lazy loading will load the data in the right time in both cases.
Regards
Hey, @Dallas62 could you please provide an example of this lazy loading?
Just don't read the data until you need it.
Olá, espero que você possa me dar uma dica. Estou enviando pushes silenciosos para o dispositivo e, em seguida, exibindo uma notificação local de dentro do
onNotification. Tudo funciona bem, exceto um cenário:Quando eu encerro o aplicativo no Android e, em seguida, envio uma notificação silenciosa para o dispositivo, o aplicativo é iniciado em segundo plano, mas
onNotificationnão é chamado para a primeira notificação que inicia o aplicativo. Para todas as notificações depois dissoonNotificationé chamado. Para mim, parecia quehandleRemotePushNotification(em Java) é chamado muito cedo para oonNotificationouvinte estar pronto, então testei isso simplesmente atrasandohandleRemotePushNotificationpor alguns segundos e isso funcionou. Em seguida, recebo oonNotificationevento corretamente também para a notificação que aciona a primeira inicialização em segundo plano.O
onRegisterevento funciona bem na primeira inicialização em segundo plano, mesmo sem atrasar o código nativo, apenas oonNotificationouvinte parece estar 'atrasado' quando o aplicativo é iniciado em segundo plano por uma notificação remota silenciosa.Isso pode ser um problema/bug ou estou fazendo algo errado ao inicializar o aplicativo ou no ciclo de vida do aplicativo para que
.configurenão esteja pronto para anexar todos os ouvintes quandojsDelivery.notifyNotificationestiver sendo chamado?Estou chamando
.configurecomo a primeira coisa diretamente doindex.jswithpopInitialNotification: trueerequestPermissions: true.react-native: 0.63.4 Versão da biblioteca: 7.0.0 Versão do Android: 9
Muito obrigado.
I'm trying to do the same thing. How did you do that? I need to show a local notification and start a background service but when the app is killed and I send a data-only notification nothing happens and onNotification is not called.