title: Other way for getActivity() use in service Android java
body: <p>In my <code>PollFragment.java</code> that able to call <code>new PollTask((MainActivity)getActivity()).execute((Void)null);</code></p>
  
  <p>And in my <code>PollTask.java</code></p>
  
  <pre><code>public PollTask(MainActivity activity){
          super(activity);
          TerminalCfg terminalCfg = Global.getTerminalCfg();
          terminalId = terminalCfg.getTerminalId();
          retailerAcc = terminalCfg.getRetailerAcc();
          internalId = APIUtil.getInternalId(activity);
          username = APIUtil.getUsername(activity);
      }
  </code></pre>
  
  <p>And now I want to call the  <code>new PollTask((MainActivity)getActivity()).execute((Void)null);</code>
  in <code>MyBackgroundService</code> with extends <code>Service</code> like below :</p>
  
  <pre><code>public int onStartCommand(Intent intent, int flags, int startId) {
          Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
          new PollTask((MainActivity)getActivity()).execute((Void)null);
          // For each start request, send a message to start a job and deliver the
          // start ID so we know which request we're stopping when we finish the job
          Message msg = mServiceHandler.obtainMessage();
          msg.arg1 = startId;
          mServiceHandler.sendMessage(msg);
  
          // If we get killed, after returning from here, restart
          return START_STICKY;
      }
  </code></pre>
  
  <p>Is there any other way to replace the <code>getActivity()</code> to call the method?</p>