Services


 

  1. StartedService
  2. IntentService
  3. Custom IntentService
  4. IntentService with ResultReceiver
  5. BoundService using IBinder
  6. BoundService using Messanger
  7. JobScheduler

 

1. StartedService
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyService.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:
service_started service_started1 service_started2
Download SourceCode

 

2. IntentService
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyService.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:
service_intent service_intent1 service_intent2
Download SourceCode

 

3. Custom IntentService
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyService.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:
service_cus_intent service_cus_intent1
Download SourceCode

 

4. IntentService using ResultReceiver
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyService.java and add following code :

Step 5 : Open src -> package -> Create new class, MyReceiver.java and add following code :

Step 6 : Open AndroidManifest.xml and add following code :

ScreenShot:
service_resultreceiverservice_resultreceiver2
Download SourceCode

 

5. BoundService using Binder
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyService.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:
serivce_binder serivce_binder1 serivce_binder2 serivce_binder4 serivce_binder5 serivce_binder6
Download SourceCode

 

6. BoundService using Messanger
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyService.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:
serivce_msg serivce_msg2 serivce_msg3 serivce_msg4 serivce_msg5 serivce_msg6
Download SourceCode

 

6. JobScheduler

Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.

Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyJobService.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

Step 7 : Open build.gradle(Module: app) and add following code :

ScreenShot:

jobscheduler jobscheduler_newjob jobscheduler_finishjob

Download SourceCode