3

I followed the example in the PushSharp repository at: PushSharp Android Client Sample

Everything is working great if the app is open or in the background (by hitting home or back button). If I close the app by swiping it away in the application manager I no longer receive notifications, though.

My assumption was that since the PushHandlerService is marked as a [Service] that it would remain open even when the app is closed and continue to listen for notifications. Is there a way to continue to receive notifications with the app closed, or am I just doing it wrong?

I would include code but what I've got is taken pretty much exactly from the example at the above link.

EDIT:

I tried firing PushClient.Register on app start even through the device is already registered in hopes that this would start the PushHandlerService if it wasn't started. Even with re-registering on each launch of the app I still don't receive notification when the app is closed.

jdehlin
  • 10,909
  • 3
  • 22
  • 33

4 Answers4

8

Did you tried it with debug, or release mode? I experienced the same when I started my app in Debug mode.

Adam Ivancza
  • 2,459
  • 1
  • 25
  • 36
  • 1
    This helped me a lot. I was not seeing the push notification come through when I'd swipe away my app, but when I tried in the release build configuration, it worked perfectly! – irreal May 21 '15 at 11:48
  • After commenting out `debuggable true` in my gradle build config, I was able to receive notifications on my S8 with the app closed and cleared from the recent apps. Thanks for the tip! – Westy92 Sep 26 '18 at 16:19
1

So, turns out that some Android devices battery or protected Apps settings causes the notification not to display. For example, in Huawei EMUI devices going to "Protected apps" settings and turning on the protected switch enables the app to receive push notification even after the app is terminated.

Alish Giri
  • 1,855
  • 18
  • 21
0

This behavior might be device specific. I experienced the same with Huawei devices using EMUI. Could solve it by adjusting the battery saving settings.

See this question: Remote Push Notifications and terminated Apps

jn-se
  • 238
  • 2
  • 9
0

If you want your service to keep running even if the application is killed then you should add the following in the service tag in your AndroidManifest.xml file.

android:stopWithTask="false"

OR

If you are using GCM for push notification and want to run the service when the notification arrives then you have to register your service as the GCM receiver in your AndroidManifest.xml file. You can do this by adding the following code

<service
    android:name=".yourPushService"
    android:exported="false">
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
    </intent-filter>
 </service>