question

khatauli-9225 avatar image
0 Votes"
khatauli-9225 asked JarvanZhang-MSFT edited

How to keep listening to android system notifications while device is in sleep mode

Hi there, I have implemented a launcher using Xamarin Android. I would like to listen to system notifications even when the device is in sleep mode. Do I need to implement it using some kind of background service, or is there a simpler way to do it.

dotnet-android
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT edited

Hello,​

Welcome to our Microsoft Q&A platform!

Hi, khatauli-9225. Starting in Android 8.0 (API level 26), an Android application no longer have the ability to run freely in the background. When an application moves into the background, Android will grant the app a certain amount of time to start and use services. Once that time has elapsed, the app can no longer start any services and any services that were started will be terminated.

To perform a background task for a long time, try using a foreground service instead.

Check the doc: https://docs.microsoft.com/en-us/xamarin/android/app-fundamentals/services/foreground-services

Similar issue: https://stackoverflow.com/questions/58107522/how-to-create-a-never-ending-background-service-in-xamarin-forms

Best Regards,

Jarvan Zhang



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.