title: ava.lang.IllegalStateException: Could not execute method of the activity
body: <p>I have two events one execute a AsincTask the other cancel the task.
  The first time I press On it works fine but when I turn Off and turn On again i'm getting a exception</p>
  
  <p>Event On:</p>
  
  <pre><code>    public void onClick(View view){
      System.out.println("onClick");
      mTask.execute();
      setActivityBackgroundColor(getResources().getColor(android.R.color.holo_green_light));
  }
  </code></pre>
  
  <p>And Event Off</p>
  
  <pre><code> public void onClick2(View view){
  
  
      System.out.println("Off");
      mTask.cancel(true);
      View view2 = this.getWindow().getDecorView();
      view2.setBackgroundColor(getResources().getColor(android.R.color.holo_red_light));
  
  }
  </code></pre>
  
  <p>The first time I press On it works fine but when I turn Off and turn On again i'm getting this exception</p>
  
  <pre><code>03-08 13:36:03.874  24510-24510/com.example.soad.sms E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: com.example.soad.sms, PID: 24510
  java.lang.IllegalStateException: Could not execute method of the activity
          at android.view.View$1.onClick(View.java:3828)
          at android.view.View.performClick(View.java:4443)
          at android.view.View$PerformClick.run(View.java:18475)
          at android.os.Handler.handleCallback(Handler.java:733)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:136)
          at android.app.ActivityThread.main(ActivityThread.java:5070)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
          at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.reflect.InvocationTargetException
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at android.view.View$1.onClick(View.java:3823)
  </code></pre>
  
  <p>    </p>
  
  <pre><code>at android.view.View.performClick(View.java:4443)
          at android.view.View$PerformClick.run(View.java:18475)
          at android.os.Handler.handleCallback(Handler.java:733)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:136)
          at android.app.ActivityThread.main(ActivityThread.java:5070)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
          at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.IllegalStateException: Cannot execute task: the task has already been executed (a task can be executed only once)
          at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:579)
          at android.os.AsyncTask.execute(AsyncTask.java:535)
          at com.example.soad.sms.MainActivity.onClick(MainActivity.java:21)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at android.view.View$1.onClick(View.java:3823)
          at android.view.View.performClick(View.java:4443)
          at android.view.View$PerformClick.run(View.java:18475)
          at android.os.Handler.handleCallback(Handler.java:733)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:136)
          at android.app.ActivityThread.main(ActivityThread.java:5070)
          at java.lang.reflect.Method.invokeNative(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:515)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>        </p>
  
  <p>Full code of activity</p>
  
  <pre><code>    public class MainActivity extends ActionBarActivity {
                private xSend mTask = new xSend();
                boolean loop = false;
     @Override
  protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      xSend mTask = new xSend();
  }
  
  
  public void onClick(View view){
      System.out.println("onClick");
      mTask.execute();
      setActivityBackgroundColor(getResources().getColor(android.R.color.holo_green_light));
  }
  
  public void setActivityBackgroundColor(int color) {
      View view = this.getWindow().getDecorView();
      view.setBackgroundColor(color);
  }
  
  public void onClick2(View view){
  
  
      System.out.println("Off");
      mTask.cancel(true);
      View view2 = this.getWindow().getDecorView();
      view2.setBackgroundColor(getResources().getColor(android.R.color.holo_red_light));
  
  }
      @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.menu_main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
  
      //noinspection SimplifiableIfStatement
      if (id == R.id.action_settings) {
          return true;
      }
  
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p>}</p>