3

I have a service, which monitors a server for changes.

When I open the app and just press my home button to leave it, all works fine.

But when I kill the app from the "recent apps" view, I don't get any notifications anymore.

I know that there is way, to use startForeground. But then I have to display a notification.

But how does the stackoverflow app work? There is no notification, no entry in the android account manager or anywhere else. But without starting it and without keeping it in the recent view, I get notifications for new answers.

How does it work?

comrade
  • 4,590
  • 5
  • 33
  • 48
Zoker
  • 2,020
  • 5
  • 32
  • 53
  • Push messages probably – Tim Jul 01 '16 at 11:58
  • 2
    @Zoker You can use [OneSignal](https://onesignal.com/) for push notifications its totally free. They using push notifications.You need to subscribe any channel to get notifications like `Stackoverflow` app. Also i dont think but maybe you need `STICKY_SERVICE` : [Service difference](http://stackoverflow.com/questions/9093271/start-sticky-and-start-not-sticky) – Yasin Kaçmaz Jul 01 '16 at 12:07
  • @Zoker sorry for second comment cannot edit first one. Go through `OneSignal`'s android guides. At finish you will be able to send push notifications from `OneSignal` to subscribed android clients. But i think you need to create a `Webservice`. Then you will be able to send notifications from `Webservice` too. – Yasin Kaçmaz Jul 01 '16 at 12:23
  • Is OneSignal better than the firebase notification module? – Zoker Jul 01 '16 at 12:24
  • @Zoker `OneSignal` is totally free but you need to create a `Webservice` for notifications etc. In Firebase` you can use [FCM](https://firebase.google.com/docs/cloud-messaging/) which replaces on `GCM` . You can start free at `Firebase` but if your app grow you need to change your plan . You can take a look at [Firebase Pricing](https://firebase.google.com/pricing/) – Yasin Kaçmaz Jul 01 '16 at 12:27
  • It will be a app only for me and my friends, so that should be fine at this point :) Thank you very much! – Zoker Jul 01 '16 at 12:28
  • 1
    @Zoker if you go pricing page you will see this: "Generous limits for hobbyists" for free accounts. Yes you can use firebase. It has tons of pros. You can see user count, login and signup users push notifications etc. – Yasin Kaçmaz Jul 01 '16 at 12:30

1 Answers1

2

Try to start service in another process. This way even if you kill your app through "recent apps", the other process (in which the service runs) will continue running. Also, on the onStartCommand of service, return START_STICKY. This will tell the OS, if for any reason you need to close the service run it again when you have enough resources.

Sorry I do not have enough reputation to put it as comment.

apersiankite
  • 531
  • 2
  • 11