Share via

How to implement notification service? (Andriod)

валера карманов 396 Reputation points
2024-10-13T18:01:12.6533333+00:00

There is a task. In the background task, send HTTP requests every minute to the server to check for notifications.

I'm stuck on the fact that I don't know how to implement a background task. It can be used "Task" to run in a separate thread without waiting for the result (it won't be there anyway). or use services.

But then my head is a little confused.

Let's say it would be more correct to implement using a service, but then from what I found out, the service is executed in the same process as the application itself. And it turns out that the service launches "Task" which is already executed in a separate process. Then what the hell do you need a service for.

The background task itself is not resource-intensive, 1 HTTP request per minute and processing of the received data, nothing complicated.

And by the way, the question is, can the background task interact with the application itself. I need the application to also have a mark that there are notifications and their number.

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author

  1. Bruce (SqlWork.com) 84,061 Reputation points
    2024-10-13T18:30:57.63+00:00

    The mobile o/s put restrictions on background tasks. They don’t want the app polling for data when not the active app. Instead they supply a notification service that a registered server can send messages to the app and receive when not active. The app has a limited resources to respond. Also if the o/s is in low resources mode, it will hold and delay notifications.

    you can use a background task and poll while the app is the active app. So a Maui background task is perfect when active. When not active you should be using notifications.

    https://developer.apple.com/documentation/usernotifications

    https://developer.android.com/develop/ui/views/notifications

    azure has a server side that supports multiple platforms

    https://azure.microsoft.com/en-us/products/notification-hubs

    Was this answer helpful?

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.