Reputation: 7517
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?
Upvotes: 9
Views: 722
Reputation: 451
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.
Upvotes: 8