Presentation is loading. Please wait.

Presentation is loading. Please wait.

Services 1 CS440. What is a Service?  Component that runs on background  Context.startService(), asks the system to schedule work for the service, to.

Similar presentations


Presentation on theme: "Services 1 CS440. What is a Service?  Component that runs on background  Context.startService(), asks the system to schedule work for the service, to."— Presentation transcript:

1 Services 1 CS440

2 What is a Service?  Component that runs on background  Context.startService(), asks the system to schedule work for the service, to be run until the service or someone else explicitly stop itContext.startService()  Facility for application to expose to other apps  Context.bindService(), allows a long-standing connection to be made to the service in order to interact with it. Context.bindService()  Not a separate process  Not a thread CS440 2

3 IntentService  Used to perform a certain task in the background  Once done it terminates itself automatically  Example: download a certain resources from the Internet. CS440 3

4 IBinder  Used by the activity to communicate with the Service. CS440 4

5 Create a simple local service  Start a new android project named SimpleService  Create a service class that extends android.app.Service.  This service just displays a message when started and again displays a message when stopped. Hence theonStart() and onDestroy() methods are implemented Use Toast with a long message display to display messages CS440 5

6 Create a simple local service  An entry for this service needs to be made in the AndroidManifest.xml file: CS440 6

7 Create a simple local service  We need to be able to invoke this service, i.e., start the service and stop the service.  Write an activity that can start and stop the service. This activity is called SimpleServiceActivity  It can have a button to start the service  It can also have a button to end the service  Do not forget the OnClickListeners!!! CS440 7

8 References  http://www.vogella.com/articles/AndroidServices/ article.html http://www.vogella.com/articles/AndroidServices/ article.html CS440 8


Download ppt "Services 1 CS440. What is a Service?  Component that runs on background  Context.startService(), asks the system to schedule work for the service, to."

Similar presentations


Ads by Google