58.5 Starting the Service
Now that the service has been implemented and declared in the manifest file, the next step is to add code to start the service when the button is clicked. Locate and load the MainActivity.java file into the editor and implement the buttonClick() method to add the code to start the service:
package com.ebookfrenzy.serviceexample;
.
.
import android.content.Intent;
import static androidx.core.app.JobIntentService.enqueueWork;
public class MainActivity extends AppCompatActivity {
static final int SERVICE_ID = 1001;
.
.
public void buttonClick(View view) {
Intent intent = new Intent();
enqueueWork(this, MyJobIntentService.class, SERVICE_ID, intent);
}
}
The code declares a service id (this can be any integer value) which is used...