2

Why doesn't the service work all the time in the background when the screen is off + USB not connected?

Using Qt, I created a test android service that uses QTimer to issues Push-notifications every 5-seconds. I did this to monitor whether the service will be always running in the background.

However, after turning the screen off, I get the notifications for around 30 seconds(total:5 or 6), then I get nothing for like 2-3 minutes. Then I get one notification after. Then I get nothing again.

I tried all of the following with no solution:

*return START_STICKY_COMPATIBILITY;
*return START_STICKY;

*Using Power Manager:

powerManager = (PowerManager)m_instance.getSystemService(Context.POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
wakeLock.acquire();

Manifest:

<uses-permission android:name="android.permission.WAKE_LOCK"/>

Btw, the service is not killed, as once i turn Back-On the screen, it resumes.

Why doesn't the service work all the time in the background when the screen is off + USB not connected?

Mena
  • 3,019
  • 1
  • 25
  • 54
  • Same problem. I brick my brain. Do you find solution? – AlexS Dec 18 '18 at 13:50
  • Yes, what is causing that is a limitation added by Google starting API 23 called "Doze mode". Starting Oreo there are even more limitations on services. So, keeping a service always running is no longer an option unless you use a foreground service. – Mena Jan 23 '19 at 09:21

0 Answers0