Ad

Xamarin.Android - Keep The App Working In Background After Closing It With A Local Notification

Currently, I have a mobile application written in Xamarin.Android. Because there are constant HTTP requests going on in the app, what I'd like to do is keep the application active after closing it.

What I am looking at, is for example after you close the app, in the background it keeps sending HTTP requests, but there is a local notification where when you click it you can open the app. There should be an explicit button for the exit which could be inside the application. In more details, HTTP requests are sent on some interval in seconds.

So my end goal is to have the app constantly running, if it's in a background, then show a notification that it's still up and be able to close it (even from the background) only from the inside of the app.

I couldn't find many resources specifically about this question and I am not quite sure what I can use in order to make this work.

Thanks in advance!

Ad

Answer

According to the documentation what you're trying to do is supported:

Sending notifications to the user

When a service is running, it can notify the user of events using Toast Notifications or Status Bar Notifications.

A toast notification is a message that appears on the surface of the current window for only a moment before disappearing. A status bar notification provides an icon in the status bar with a message, which the user can select in order to take an action (such as start an activity).

Usually, a status bar notification is the best technique to use when background work such as a file download has completed, and the user can now act on it. When the user selects the notification from theexpanded view, the notification can start an activity (such as to display the downloaded file).

See the Toast Notifications or Status Bar Notifications developer guides for more information.

ref: https://developer.android.com/guide/components/services
ref: https://developer.android.com/guide/components/processes-and-threads

Ad
source: stackoverflow.com
Ad