title: How to get rid of 'Service not registered: android.speech.SpeechRecognizer' error in Android
body: <p>I'm letting my users to use SpeechRecognizer and some kind of phones and android versions get an error which is "Service not registered: android.speech.SpeechRecognizer". </p>
  
  <pre><code>if (speech != null) {
    speech!!.stopListening()
    speech!!.cancel()
    speech!!.destroy() // PictureVoiceActivity.kt:489
  }
  //
  viewPager.setCurrentItem(viewPager.currentItem + 1, true) speech!!.destroy() // PictureVoiceActivity.kt:360
  </code></pre>
  
  <p>Error log:</p>
  
  <pre><code>Fatal Exception: java.lang.IllegalArgumentException: Service not registered: android.speech.SpeechRecognizer$Connection@2d1871c9
         at android.app.LoadedApk.forgetServiceDispatcher + 1151(LoadedApk.java:1151)
         at android.app.ContextImpl.unbindService + 2253(ContextImpl.java:2253)
         at android.content.ContextWrapper.unbindService + 572(ContextWrapper.java:572)
         at android.speech.SpeechRecognizer.destroy + 408(SpeechRecognizer.java:408)
         at com.blarma.high5.aui.lesson.PictureVoiceActivity$ArrayFragment.onPause + 489(PictureVoiceActivity.kt:489)
         at androidx.fragment.app.Fragment.performPause + 2787(Fragment.java:2787)
         at androidx.fragment.app.FragmentManagerImpl.moveToState + 935(FragmentManagerImpl.java:935)
         at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState + 1240(FragmentManagerImpl.java:1240)
         at androidx.fragment.app.BackStackRecord.executeOps + 434(BackStackRecord.java:434)
         at androidx.fragment.app.FragmentManagerImpl.executeOps + 2078(FragmentManagerImpl.java:2078)
         at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether + 1868(FragmentManagerImpl.java:1868)
         at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute + 1823(FragmentManagerImpl.java:1823)
         at androidx.fragment.app.FragmentManagerImpl.execSingleAction + 1698(FragmentManagerImpl.java:1698)
         at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss + 299(BackStackRecord.java:299)
         at androidx.fragment.app.FragmentStatePagerAdapter.finishUpdate + 256(FragmentStatePagerAdapter.java:256)
         at androidx.viewpager.widget.ViewPager.populate + 1244(ViewPager.java:1244)
         at androidx.viewpager.widget.ViewPager.setCurrentItemInternal + 669(ViewPager.java:669)
         at androidx.viewpager.widget.ViewPager.setCurrentItemInternal + 631(ViewPager.java:631)
         at androidx.viewpager.widget.ViewPager.setCurrentItem + 623(ViewPager.java:623)
         at com.blarma.high5.aui.lesson.PictureVoiceActivity$ArrayFragment$onCreateView$3.onClick + 360(PictureVoiceActivity.kt:360)
         at android.view.View.performClick + 5246(View.java:5246)
         at android.widget.TextView.performClick + 10565(TextView.java:10565)
         at android.view.View$PerformClick.run + 21200(View.java:21200)
         at android.os.Handler.handleCallback + 739(Handler.java:739)
         at android.os.Handler.dispatchMessage + 95(Handler.java:95)
         at android.os.Looper.loop + 145(Looper.java:145)
         at android.app.ActivityThread.main + 6946(ActivityThread.java:6946)
         at java.lang.reflect.Method.invoke(Method.java)
         at java.lang.reflect.Method.invoke + 372(Method.java:372)
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 1404(ZygoteInit.java:1404)
         at com.android.internal.os.ZygoteInit.main + 1199(ZygoteInit.java:1199)
  </code></pre>