title: How to invoke Speechrecognizer methods from service with no main thread or activity
body: <p>I am aware that there are dozens of links on Stackoverflow and other sites about the SpeechRecognizer class and how to implement it. I have been through several of them and have searched for hours. 
  Although there are examples of implementations in services, they don't seem to work for me. </p>
  
  <p>My application has an activity, however it is only used for user settings and does not run when my service runs, which is called separately from the system. Thus my service does not have any main application thread to relate to in order to run/invoke the methods of the SpeechRecognizer class. </p>
  
  <p>As it is stated in the android docs, <a href="http://developer.android.com/reference/android/speech/SpeechRecognizer.html" rel="nofollow noreferrer">here</a>: </p>
  
  <blockquote>
    <p>'This class's methods must be invoked only from the main application thread.'</p>
  </blockquote>
  
  <p>When I run my code including the SpeechRecognizer.startListening(mSpeechRecognizerIntent) method which is in my service class I get the following error:</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: SpeechRecognizer should be used only from the application's main thread</p>
  </blockquote>
  
  <p>Is there a way to solve this problem? I have read that the SpeechRecognizer can 'recognize speech while running in the background or from a service', I found that here:</p>
  
  <p><a href="https://stackoverflow.com/questions/11913704/comparison-of-speech-recognition-use-in-android-by-intent-or-on-thread">Comparison of Speech Recognition use in Android: by Intent or on-thread?</a></p>
  
  <p>So that is basically what I want I just can't seem to get the SpeechRecognizer started because I get the mentioned error.
  Could you also tell me whether it is necessary to call the following methods in the application's main thread (,which i don't have):</p>
  
  <blockquote>
    <p>mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
    mSpeechRecognizer.setRecognitionListener(new SpeechRecognitionListener());</p>
  </blockquote>
  
  <p>My code is basically identical to the code in the top answer of this link: (without the IncomingHandler class, which I believe is only used to control the timing of the listener)</p>
  
  <p><a href="https://stackoverflow.com/questions/14940657/android-speech-recognition-as-a-service-on-android-4-1-4-2/14950616#14950616">Android Speech Recognition as a service on Android 4.1 &amp; 4.2</a></p>
  
  <p>Would really appreciate some help, thanks in advance.
  This is my first android application so I am pretty new to it, please bear with me ;)</p>