Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass Parameters To GcmTaskService

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?

like image 584
Jude Fernandes Avatar asked Jul 19 '15 14:07

Jude Fernandes


1 Answers

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.

like image 86
Dearmash Avatar answered Nov 01 '22 23:11

Dearmash