Android - What is the difference between foreground and background services?

Android.com states that the foreground service is something the user is aware of, and the foreground service is unlikely to be killed if memory is needed. It says that background service can be killed if memory is required. Is this the only difference or can one service offer additional functions?

My main question is why use a background service when it can be killed. Can anyone provide a sample application to use a background service?

+3


source to share


1 answer


Is this the only difference or can one service offer additional features?

To have a foreground function, you must show Notification

in the status bar. Ideally, Notification

it gives the user control over the application, such as stopping anything that the foreground service is doing (such as playing music).

why use a background service if it can be killed

Among other reasons, users are very upset if they add icons to their status bar without a good justification for their presence.



In general, you don't use any type of service unless it actively delivers value to the user . Many background services are short-lived, do some work (like checking the mail server for new messages) and leave. There is no compelling reason to have a front end service for this job, although some developers will do it anyway.

Can anyone provide a sample application to use a background service?

Most apps on your device use background services.

+9


source







All Articles