title: Broadcasting an intent from a fragment to a service
body: <p>In an activity, when I send an intent to a service I just use <code>sendBroadcast</code>, but I cannot do the same from a fragment because a fragment has to be a static class. What is the best way of dealing with this?</p>
  
  <p>I have considered having a method that receives a context, but this wouldn't work in the case of a fragment.</p>
  
  <p>Currently my code is </p>
  
  <pre><code>public static class ExampleSectionFragment extends Fragment {
      public static final String ARG_SECTION_NUMBER = "section_number";
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragment_section_example, container, false);
          Bundle args = getArguments();
  
          //Example intent to broadcast to service on button press
          rootView.findViewById(R.id.action_start)
                  .setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Intent intent = new Intent(RECORDING_INTENT);
                           sendBroadcast(intent);
                      }
                  });
          return rootView;
      }
  }
  </code></pre>
  
  <p>sendBroadcast returns the error in eclipse:</p>
  
  <blockquote>
    <p>Cannot make a static reference to the non-static method sendBroadcast(Intent) from the type ContextWrapper</p>
  </blockquote>