Course Content

Course Content

Services Example in Android

Example of an Android Service


In this video we are going to see an example for Android service.

Firstly we have taken 1 relative layout and inside that we have two buttons, start service and stop service.

Now inside our Java folder we have another folder named as 'com.example.androidservice' we will create new class naming it as 'Myservice'. New class will be successfully created.

Now we need to implement it's Onbind methods, and use different methods further.


public IBinder onBind(Intent intent)


return null;



public void onCreate()


Toast.makeText(this,"Service was Created", Toast.LENGTH_LONG).show();


By similar method we will use Onstart() method by passing Intents.

Now in our file, we will create startService,

public void startService(View view)


startService(new Intent(this,MyService.class));

public void stopService(View view)


stopService(new Intent(this,MyService.class));

Now we will run our code and see that, when we click on start service button, the toast notification 'Service was created' and 'Service started' appears on our screen. And then when we click on our second button stop service, the toast notification 'Service destroyed' appear.

So in this way in our Android application we can create service.


Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
App Store
397K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
13K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere