Nick
Nick

Reputation: 2928

Android Thread AND Services Priorities

I was reading in the Web (Why to use Service if it runs in the same thread in android) about Services and Threads and i came to a conclusion that in general Services have a higher priority than Thread.

I have an app that executes a download operation using simple Threads via a static class and completes in 5 minutes. But when i press Home button and after a while open the app again the execution went slower because i pressed the home button.

What am i asking is, if i use a service will go faster or by pressing the home button it is normal to slow down the apps or priorities are irrelevant all together with the execution time?

Thank you.

Upvotes: 1

Views: 270

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93561

No, they don't. Service aren't an execution context, they don't have a priority at all. I'm not sure where you got that idea from, but its like saying peanuts have a higher priority than volleyball. It just doesn't make sense.

Now whatever an app is in the foreground will generally get the CPU first, but downloading isn't a CPU intensive operation. Its network intensive. You'll have no problem getting the CPU long enough to read from the socket, even if backgrounded.

The point of a Service is that it provides a Context, yet isn't tied to any UI, any screen of your app, or your app being in the foreground. Its a place you can do background processing, or process data needed by multiple Activities. That's it, it has nothing to do with threading or priorities.

Upvotes: 1

Related Questions