Should I use Remote Service Binding for a background task ?

Tutorials with advanced 'difficulty' and more Lines of Code.

Should I use Remote Service Binding for a background task ?

Postby aibo99 » Mon Oct 05, 2009 7:22 am

Hello,

I am very new beginner, and I am designing a small application as below.

- After a user starts the application, he/she can click the start button to start a background task. (e.g. retrieving the news headlines periodically, then do something...)

- Even after the user quits the application, the background task still running (alive).

- To stop the background task, the user needs to enter the application again, and clicks the stop button to destroy the background task.

In the above scenario, what API should I use ? (Remote Service Binding ? Handler ?)

Could I simply use Remote Service Controller in the programming ?

Please help me. Thank you very much.
aibo99
Freshman
Freshman
 
Posts: 9
Joined: Mon Oct 05, 2009 7:18 am

Top

Postby padde » Mon Oct 05, 2009 8:57 am

You have to use a remote service for this scenario.
The reason why is simple. If you use a local service
your service gets killed as soon as the user or the
system kills your app (acitivty) because service and
activity are hosted in the same process.
A remote service on the other hand is hosted in an
own process. The downside of this is you have to
use AIDL if you want to communicate with the service.

There is a great tutorial right about even with sample code
http://www.anddev.org/remote_service_tutorial-t8127.html
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby aibo99 » Mon Oct 05, 2009 9:13 am

Thank you very much for your answer and help.

Could I simply use remote service without AIDL ?

http://developer.android.com/guide/samp ... oller.html
aibo99
Freshman
Freshman
 
Posts: 9
Joined: Mon Oct 05, 2009 7:18 am

Postby padde » Mon Oct 05, 2009 10:53 am

If there is no interaction except for start and stop the service you dont need AIDL.
But for anything else like controling (more than start/stop) the service or
get response/values back from the service you need AIDL in order to overcome
the process boundary.

But AIDL isnt the devil.. its just a necessary evil and costs a bit extra work so no
need to avoid it at any price.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests