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)
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 MainActivity.java file, we will create startService,
public void startService(View view)
public void stopService(View view)
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.
Have a friend to whom you would want to share this course?