I am trying to implement a service using the GcmTaskService. This is my code in the main activity to call the service called Myservice.
OneoffTask myTask = new OneoffTask.Builder()
.setService(MyService.class)
.setExecutionWindow(0, 10)
.setTag("test-upload")
.build();
GcmNetworkManager.getInstance(this).schedule(myTask);
This is the MyService class.
public class MyService extends GcmTaskService {
@Override
public int onRunTask(TaskParams taskParams) {
Log.i("onRunTask: ", taskParams.getTag() + "");
return GcmNetworkManager.RESULT_RESCHEDULE;
}
}
What i want to know is how do i pass parameters to this service?
https://developers.google.com/android/reference/com/google/android/gms/gcm/TaskParams
TaskParams has a getExtras() which returns a bundle for you to use. This should be populated by the call to setExtras() on your TaskBuilder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With