title: Android JobScheduling - I need to pass an object to my job but how?
body: <p>I would like to use Androids new JobScheduler in my app but right now I don't know how to pass my object which contains the data (<code>byte</code> array) that should be sent via network by a job.
  I searched for an answer but so far found none I'm afraid.</p>
  
  <p>I have a JobService:</p>
  
  <pre><code>public class MyJob extends JobService {
  
      @Override
      public boolean onStartJob(JobParameters jobParameters) {
          new JobTask(this).execute(jobParameters);
          return true;
      }
  
      @Override
      public boolean onStopJob(JobParameters params) {
          return false;
      }
  
      private static class JobTask extends AsyncTask&lt;JobParameters, Void,       JobParameters&gt; {
          private final JobService jobService;
  
          public JobTask(JobService jobService) {
              this.jobService = jobService;
          }
  
          @Override
          protected JobParameters doInBackground(JobParameters... params) {
              AnotherClass.post(myObject); // where does myObject come from?
              return params[0];
          }
  
          @Override
          protected void onPostExecute(JobParameters jobParameters) {
              jobService.jobFinished(jobParameters, false);
          }
      }
  }
  </code></pre>
  
  <p>... am building a job like this:</p>
  
  <pre><code>PersistableBundle bundle = new PersistableBundle();
  JobInfo job = new JobInfo.Builder(jobID, new ComponentName(context, AshServiceJob.class))
                .setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED)
                .setPersisted(true)
                .setExtras(bundle)  // could bundle somehow contain myObject?
                .build();
  </code></pre>
  
  <p>OtherClass.addJobInBackground(job);</p>
  
  <p>... and am scheduling the job:</p>
  
  <pre><code>public void addJobInBackground(final JobInfo job) {
          JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
          jobScheduler.schedule(job);
      }
  </code></pre>
  
  <p>Sooo ... I can't call any methods in MyJob directly, right? I then thought I could use <code>.setExtras(bundle)</code> to pass my object to the job, but as I found out you can only use a <code>PersistableBundle</code> which wouldn't take a serialized object like Bundle. Setting keys and values doesn't work, because you can only put <code>booleans, ints, strings</code>, etc. but not <code>byte[]</code>, which is what I need.</p>
  
  <p>Has anyone any idea? I'm quite stuck.</p>
  
  <p>Thanks in advance,
  a-m</p>
  
  <p>PS: Sorry, if I probably didn't use the right Code-Tags.</p>