title: Unable to get a reference for quick settings tile
body: <p>I can set the state of the qs tile using the onClick() method but I would also like to toggle its state using a switch in my Main Activity. However, I can't change the state of the tile using a switch because getQsTile returns null outside the onClick() method.</p>
  
  <pre><code>public class AwesomeTileService extends TileService{
  
  Tile tile;
  public Activity activity;
  
  public AwesomeTileService(Activity activity){
      this.activity=activity;
      Switch switch1 = (Switch)this.activity.findViewById(R.id.switch1);
      switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
  
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
              tile=getQsTile(); //tile is null
  
              SwitchState(); //SwitchState does not work with onCheckedChanged
              Log.v("Switch State=", ""+isChecked);
          }
  
      });
  }
  
  public AwesomeTileService(){
      //zero arg constructor
  }
  
  
  @Override
  public void onTileAdded() {
      tile=getQsTile();
  
  
      tile.setState(Tile.STATE_INACTIVE);
      tile.updateTile();
  }
  
  @Override
  public void onClick() {
  
      tile=getQsTile(); //tile is not null
      SwitchState(); //SwitchState method works with onClick
  }
  
  public void SwitchState(){
  
      if(tile!=null){
          if (tile.getState() == Tile.STATE_INACTIVE) {
              tile.setState(Tile.STATE_ACTIVE);
          }
          else{
              tile.setState(Tile.STATE_INACTIVE);
          }
          tile.updateTile();
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I can simply remove the switch from the app but I'm curious to know what the issue is here and how I can overcome it. </p>