title: getApplicationContext() not working for JobScheduler which uses AsyncTask for JobService
body: <p>I am using <code>JobScheduler</code> which uses <code>AsyncTask</code> for its <code>JobService</code>. In the class <code>MJobExecutor</code> which extends <code>AsyncTask</code> uses <code>MediaPlayer</code> which needs <code>getApplicationContext()</code> as argument is not working. It shows cannot resolve method.</p>
  
  <pre><code>public class MJobExecutor extends AsyncTask&lt;Void,Void,String&gt; {
  ValueExchange value;
  MediaPlayer player;
  
  @Override
  protected String doInBackground(Void... params) {
  
      value = new ValueExchange();
      Calendar cal = Calendar.getInstance();
      Date date=cal.getTime();
      DateFormat dateFormat = new SimpleDateFormat("hh:mm a");
      String formattedDate=dateFormat.format(date);
      if(formattedDate.equals(value.getString())){
  
      }
      return "Long running task finishes." + value.getString();
  }
  
  private void play(){
      if(player == null){
  
          player = MediaPlayer.create(getApplicationContext(),R.raw.bensoundfunkyelement);
          //In the above code getApplicationContext() not working-
          //Cannot resolve method getApplicationContext()
          //i have used this as context not working.
          //getBaseActivity() not working.
          //getActivity().getApplicationContext() also not working.
  
  
        player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
              @Override
              public void onCompletion(MediaPlayer mp) {
                  stopPlayer();
              }
          });
      }
      player.start();
  }
  private void stop(){
      stopPlayer();
  }
  private void stopPlayer(){
      if(player != null){
          player.release();
          player = null;
      }
  }
  
  
  }
  </code></pre>
  
  <p>Below is the <code>MainActivity</code> file. There is no problem in this file.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  private static final int JOB_ID = 101;
  JobScheduler jobScheduler;
  JobInfo jobInfo;
  
  
  
  TextView textTime;
  ImageButton ibLeft,ibRight,ibTop,ibBottom;
  TextClock textClock;
  
  
  
  String alarmTime = "12:00 AM";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
  
      textTime = (TextView)findViewById(R.id.textView);
      ibLeft = (ImageButton)findViewById(R.id.left);
      ibRight = (ImageButton)findViewById(R.id.right);
      ibTop = (ImageButton)findViewById(R.id.top);
      ibBottom = (ImageButton)findViewById(R.id.bottom);
  
      textClock.setPadding(0,250,0,0);
  
  
      ComponentName componentName = new ComponentName(this,MJobScheduler.class);
      PersistableBundle bundle = new PersistableBundle();
      bundle.putString("alarmTime",alarmTime);
  
      JobInfo.Builder builder = new JobInfo.Builder(JOB_ID,componentName);
  
      builder.setExtras(bundle);
      builder.setPeriodic(5000);
      builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
      builder.setPersisted(true);
      jobInfo = builder.build();
      jobScheduler = (JobScheduler) getSystemService(JOB_SCHEDULER_SERVICE);
  
  
  
  }
  
  
  public void Start(View view) {
  
      jobScheduler.schedule(jobInfo);
      Toast.makeText(this,"Job Started...",Toast.LENGTH_LONG).show();
  }
  
  public void Stop(View view) {
      jobScheduler.cancel(JOB_ID);
      Toast.makeText(this,"Job Cancelled...",Toast.LENGTH_LONG).show();
  }
  
  
  }
  </code></pre>
  
  <p>Below is <code>MjobExecutor</code> class which extends <code>JobService</code> calls <code>MJobExecutor</code> class which extends <code>AsyncTask</code>. It seems there is also no problem in this class.</p>
  
  <pre><code>public class MJobScheduler extends JobService {
  MJobExecutor mJobExecutor;
  String alarmTime;
  ValueExchange value;
  
  @Override
  public boolean onStartJob(final JobParameters params) {
      alarmTime = params.getExtras().getString("alarmTime");
      value = new ValueExchange();
      value.setString(alarmTime);
      mJobExecutor = new MJobExecutor(){
  
          @Override
          protected void onPostExecute(String s) {
              Toast.makeText(getApplicationContext(),alarmTime+" "+s,Toast.LENGTH_LONG).show();
              jobFinished(params,false);
          }
      };
      mJobExecutor.execute();
      return true;
  }
  
  @Override
  public boolean onStopJob(JobParameters params) {
      mJobExecutor.cancel(false);
      return false;
  }
  }
  </code></pre>