googlearchive/androidtv-Leanback

Crash in SearchSupportFragment at onStop

Ryder68 opened this issue · 13 comments

Hi.
I'm working with SearchSupportFragment, but when stop, app crashes at onStop with error:
SearchFragment Service not registered: android.speech.SpeechRecognizer.
Please help me.
I'm using com.android.support:leanback-v17:27.1.1

Thank! so much.

Hello.
Can someone help me ? :-(

Which version of the OS are you testing on?

Hi, I've come across this issue as well but to me it happened in the onPause method when a SearchSupportFragment tries to release a SpeachRecognizer. I've noticed this issue on two devices (Amlogic P212 box with Android 6.0.1 and HongXin M16 box with Android 7.1.2) which both don't have a microphone. I haven't had this issue in an emulator (API 23 and API 27), neither on a device with microphone (Amlogic P212 dongle with Android 8.1.0).

The steps to reproduce the issue are quite straightforward:
1, launch SearchSupportFragment (I have it in a separate activity)
2, system asks if you want to allow the app to record audio, you press allow
3, press return and it throws the exception below
*if you press deny in the second step, it doesn't throw the exception

java.lang.RuntimeException: Unable to pause activity {...SearchActivity}: java.lang.IllegalArgumentException: Service not registered: android.speech.SpeechRecognizer$Connection@3778628
        at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3381)
        at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3340)
        at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3315)
        at android.app.ActivityThread.-wrap13(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5422)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: java.lang.IllegalArgumentException: Service not registered: android.speech.SpeechRecognizer$Connection@3778628
        at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1044)
        at android.app.ContextImpl.unbindService(ContextImpl.java:1337)
        at android.content.ContextWrapper.unbindService(ContextWrapper.java:616)
        at android.speech.SpeechRecognizer.destroy(SpeechRecognizer.java:408)
        at android.support.v17.leanback.app.SearchSupportFragment.releaseRecognizer(SearchSupportFragment.java:433)
        at android.support.v17.leanback.app.SearchSupportFragment.onPause(SearchSupportFragment.java:409)
        at android.support.v4.app.Fragment.performPause(Fragment.java:2531)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1485)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
        at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3244)
        at android.support.v4.app.FragmentManagerImpl.dispatchPause(FragmentManager.java:3216)
        at android.support.v4.app.FragmentController.dispatchPause(FragmentController.java:228)
        at android.support.v4.app.FragmentActivity.onPause(FragmentActivity.java:447)
        at android.app.Activity.performPause(Activity.java:6363)
        at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1311)
        at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3367)
        at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3340) 
        at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3315) 
        at android.app.ActivityThread.-wrap13(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5422) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Yes.
It seems to happen on a device without a mic.
And SpeechRecognizer.isRecognitionAvailable return false.

yes same things happened to me while developing the application so here is the fix for this
need to add this in SearchActiviy inside the on create

` mFragment = (SearchFragment) getFragmentManager().findFragmentById(R.id.search_fragment);

    mSpeechRecognitionCallback = new SpeechRecognitionCallback() {
        @Override
        public void recognizeSpeech() {
            try {
                if (DEBUG) Log.v(TAG, "recognizeSpeech");
                startActivityForResult(mFragment.getRecognizerIntent(), REQUEST_SPEECH);
            } catch (ActivityNotFoundException e) {

            }
        }
    };
    mFragment.setSpeechRecognitionCallback(mSpeechRecognitionCallback);`

@anurag7141 , I will like to ask what the R.id.search_fragment is actually referencing, is that being called from a layout, and I will so much appreciate if you can share the layout as well.

Thanks.

<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/search_fragment" android:name=".SearchFragment" android:layout_width="match_parent" android:layout_height="match_parent" />

Hi meshileya,
That refers to the fragment.

public class SearchFragment extends android.support.v17.leanback.app.SearchFragment implements android.support.v17.leanback.app.SearchFragment.SearchResultProvider { .....fragment code goes here. }

Thanks @anurag7141 , I will get back to you on this...will want to make the quick fix from my end.

Same problem. If youre decided this problem write me on andreyriz2909@gmail.com.

setSpeechRecognitionCallback is deprecated:

Deprecated: Launching voice recognition activity is no longer supported. App should declare android.permission.RECORD_AUDIO in AndroidManifest file.

So, instead of manually starting activity, I think a better workaround would be setting an empty callback on devices with unavailable speech recognition (inside onCreate() of your SearchFragment):

    if (!SpeechRecognizer.isRecognitionAvailable(context)) {
            setSpeechRecognitionCallback { }
    }

This sample has been migrated to a new location and updates are happening there (check README for more information).

As recommended by GitHub, we are closing all issues and pull requests now that this older repo will be archived.

If you still see this issue in the updated repo, please reopen the issue/PR there. Thank you!