0

I am seeing my app in the following screen

https://i.stack.imgur.com/BbqqZ.jpg

If I swipe my app to the right, I notice that the process and services related to app are killed.

  1. How to avoid killing the process and services when we swipe?
  2. How to keep the service (I am using IntentService - so other
    answer mentioned for similar question doesn't work) running when the app is swiped to right?
  3. Answer mentioned here restarts (which means the service doesn't do its job for few seconds during the restart phase) the service and process. I want the service to work continuously without any drop. How to do this?
Community
  • 1
  • 1
sofs1
  • 3,834
  • 11
  • 51
  • 89
  • IntentServices are not meant to be used for long running stuff. Also, why did you tag android-service-binding? IntentServices are not meant to be bound. – Yaroslav Mytkalyk Dec 31 '16 at 18:53
  • I thought android-service-binding might be a new solution (moving entirely out of Intent services) for my use case. – sofs1 Dec 31 '16 at 19:04

1 Answers1

0

For this you need to start your service as a foreground service. Refer here under Running a service in the foreground.

If you start the service which is a background service, Android will kill it whenever memory is low. And take note, not every time that list is cleared, your service will die. It happens only when the Android system decides its low on memory.

Tharaka Devinda
  • 1,952
  • 21
  • 23
  • I went through that option. Thanks. But Is it possible to create a foreground service without notification ? – sofs1 Dec 31 '16 at 18:26
  • according to this : http://stackoverflow.com/questions/10962418/how-to-startforeground-without-showing-notification its not possible and not adviced as well. – Tharaka Devinda Dec 31 '16 at 18:37
  • I was just reading that. My app is liek Facebook or Whatsapp where if a message is sent, it has to be shown immediately to the user. For that the app has to be continuously talking to my web server. So the service that talks to web server should always be up and running (there shouldn't be no restart - user forcefully killing is fine). – sofs1 Dec 31 '16 at 18:41
  • I just read this https://www.reddit.com/r/androiddev/comments/1uqpwv/a_query_about_android_service_startforeground/cel9mdg/ I think push notifications would work. Any suggestions on push notifications for my use case. – sofs1 Dec 31 '16 at 18:50