To do some back ground functionality in an activity, which is better ? thread or service?

A. thread is better as long as thread is closely related with your UI and as long as programmer make sure that cleaning and creation of thread is done properly.
B. it is better to use services with thread, because threads in activity will have less priority compared to thread in a service in case if that activity is in background or stopped state. more over in case of low memory if it kills thread in activity, there is no way that android will recreate it. all these disadvantages are overcome in services with android.

C. you can either use option 1 or option 2, based on your requirement. But most of the times it is better to use option 2.
D. Both thread and service are back ground components, so you can use either of them.


Answer: C

Description:
it is better to use services with thread, because threads in activity will have less priority compared to thread in a service in case if that activity is in background or stopped state. more over in case of low memory if it kills thread in activity, there is no way that android will recreate it. all these disadvantages are overcome in services with android. But still if you want to use a thread with activity then as long as programmer make sure that cleaning and creation of thread is done properly, then there won't be any problem.

No comments:

Post a Comment