question

jessejoh avatar image
jessejoh asked Alan commented

Clover Notifications when app is closed

Hello there,

I have used the notifications example to produce something that (mostly) works. I have noticed that the app must be already open in order to receive/process the notification. If it is not opened, the app opens up, but does not process the notification.

Can you point me in the right direction? If the app is not already opened, I would like it to open (which it is doing) and process the notification (not doing).

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeffrey Blattman avatar image
Jeffrey Blattman answered

The app notification comes as a broadcast. If you've registered your receiver in your manifest, it doesn't need to be "open". Android will start your receiver to handle the broadcast.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Alan avatar image
Alan answered Alan commented

I have a class extending AppNotificationReceiver, with the following in my manifest file:

<receiver
 android:name=".services.NotificationReceiver"
 android:enabled="true"
 android:exported="true" >
 <intent-filter>
          <action android:name="com.clover.sdk.app.intent.action.APP_NOTIFICATION"/>
 </intent-filter
</receiver>

The onReceive method is triggered perfectly while the app is in the foreground and also while its "closed"(IE while on home screen, or another app). However, it doesn't seem to be called after the app is forcibly closed. Any suggestions? @jeff

4 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

If your app is killed our crashes repeatedly Android will disable the app. Do you know if that's happening (what do you mean by "forcibly closed")?

0 Likes 0 ·
Alan avatar image Alan commented ·

Thanks Jeff, no crashing occuring for my app. By forcibly closed I mean clicking the android burger icon and swiping the app away to close. Its consistently not working after doing so, our worry is that we can't show notifications after a merchant has restarted their device and not opened our app for the day. I have a receiver defined in the manifest as suggested, can you think of any other reason notifications don't start our receiver while the app isn't in the background?

0 Likes 0 ·
Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

Swiping away recents should not "force close" the app (per the definition of force close). It should only remove the task you swipe away. I did some tests here and my app was able to receive broadcasts after being swiped away. If your app is being force closed, that should be apparent in the logs. Can you 1) capture the logs of the behavior and 2) write a sample app that demonstrates the same?

0 Likes 0 ·
Alan avatar image Alan commented ·

Thanks Jeff, good to hear it should work. I'll try again with a stripped down app and get back to you

0 Likes 0 ·

Welcome to the
Clover Developer Community