Skip to content
This repository has been archived by the owner on Sep 28, 2019. It is now read-only.

Crash in SearchSupportFragment at onStop #118

Closed
Ryder68 opened this issue May 10, 2018 · 13 comments
Closed

Crash in SearchSupportFragment at onStop #118

Ryder68 opened this issue May 10, 2018 · 13 comments

Comments

@Ryder68
Copy link

Ryder68 commented May 10, 2018

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.

@Ryder68
Copy link
Author

Ryder68 commented May 11, 2018

Hello.
Can someone help me ? :-(

@Fleker
Copy link
Contributor

Fleker commented May 11, 2018

Which version of the OS are you testing on?

@okycelt
Copy link

okycelt commented May 16, 2018

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)

@Ryder68
Copy link
Author

Ryder68 commented May 18, 2018

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

@Ryder68
Copy link
Author

Ryder68 commented May 18, 2018

@Fleker

@anurag7141
Copy link

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);`

@meshileya
Copy link

@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.

@anurag7141
Copy link

<?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. }

@meshileya
Copy link

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

@andreyriz
Copy link

andreyriz commented May 2, 2019

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

@akishindev
Copy link

akishindev commented Sep 10, 2019

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 { }
    }

@andreyriz
Copy link

andreyriz commented Sep 10, 2019 via email

@codingjeremy
Copy link
Contributor

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants