Cody Cody - 1 year ago 85
Android Question

When to use a thread / service in Android?

When should a thread or a service be used?

Should they be used for authentication? For instance, in my app I was considering using a thread or service (I am authenticating via Active Directory.)

Do you have examples of when each would be used?

Answer Source

A thread should be used in a long running process that would block the UI from updating. If it's more than a second or two you might want to put it into a background thread and notify the user with a dialog or spinner or something. If you lock the UI thread for more than 5 seconds the user will be prompted with a kill or wait option by the OS.

A service does not run on separate thread, so it will block the UI, but you can spawn a new thread within a service. A service is used more for something that should happen on an interval or keep running/checking for something when there is no UI shown.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download