1

I am working on an application related to Voip & IM (chatting application). Till android OS 5.0 it is working good and no issues from client also. But from android OS 5.1.1 onwards we are facing issues.

Issues:

  • If the app is in foreground and if device goes to sleep mode it is working good.
  • If the app is in background and if device goes to sleep mode after 10 minutes all the services are stopping automatically.

Testing:

  • For testing I created one timer task to print logs for every 1 minute. So when I close the application (means if the app is in background)

  • Till android OS 5.0 logs are printing continuously.

  • From android OS 5.1.1 onwards after going to sleep mode, after 10 minutes logs are not printing. Timer task is stopping

Same problem I am facing for my application also.

After doing some R&D I came to know regarding doze mode and app optimization. Is it anyhow related to stop services automatically running in background.

If yes, can anyone please let me know how to overcome this issue.

user2384424
  • 187
  • 1
  • 3
  • 13
  • do you use foregroundService? – Vladyslav Matviienko Jul 04 '17 at 05:28
  • doze mode is first introduced in Marshmallow and redefined in Nougat. If your service is stopping in Android version 5.1.1 then you may have other problems. Just checking, Did you use `START_STICKY` for your service ? – tahsinRupam Jul 04 '17 at 05:53
  • @tahsinRupam Yes I used START_STICKY. Till 5.0 it is working good. We are facing this issue from 5.1.1 onwards and that too testing applications timer task is also not working after going to sleep mode. – user2384424 Jul 04 '17 at 05:55
  • @tahsinRupam and Vlad Matvienko, for testing I installed SIPDroid application from play store. This is also same problem. after device goes to sleep mode in 10 minutes the services are stopping. – user2384424 Jul 04 '17 at 06:02
  • 1
    You can use a foreground service as Vlad Matvienko said. It will create a Notification that will tell the service is running. You can check this tutorial if you may - http://www.truiton.com/2014/10/android-foreground-service-example/ – tahsinRupam Jul 04 '17 at 06:08
  • What devices are you using for testing (ie: what devices do you see this behaviour on?) – David Wasser Jul 05 '17 at 19:57

1 Answers1

1

This is new thing which google done to prevent unwanted battery usage. For new versions the background services are restricted for better battery life. The android service consumes almost same as the application running in foreground. So even though app is not running its services may be running and using memory and battery.

If you have to use any kind of background process try to use Job Scheduler which may be something useful for you.

The Job Scheduler groups the task and execute the background task based on the constraints we provide in the implementation. This have a limitation it support on minimum API 21

To support on lower version you can use Firebase JobDispatcher which support from API 9.

I personally prefer Firebase JobDispatcher

This link help you to understand more about scheduler and its implementation.

callmejeevan
  • 1,040
  • 1
  • 9
  • 18