MainActivity has leaked ServiceConnection android.speech.SpeechRecognizer$Connection@414ee400 that was originally bound here

后端 未结 3 1554
南笙
南笙 2021-01-17 22:34

In my app I recognize the user saying \"exit\" or \"close\" and the app should close. With this code

SpeechRecognizer sr;
Map dictiona         


        
相关标签:
3条回答
  • 2021-01-17 22:51

    The problem was the most trivial ever: I declared the SpeechRecognizer two times, one for the class and another inside the onCreate() method. The variable was initialized only in the function scope, so outside the function sr was always null.

    0 讨论(0)
  • 2021-01-17 23:03

    My solution for Dialog:

    public void dismiss(){
        speech.stopListening();
        try{
            speech.destroy();
        }
        catch (Exception e)
        {
            Log.e(TAG,"Exception:" + e.toString());
        }
        super.dismiss();
    }
    
    0 讨论(0)
  • 2021-01-17 23:18

    I think problem may be at line:

    sr.destroy();
    

    If sr be null, you get NullPointerException, and

    super.onDestroy();
    

    Dont has been called. Try do next:

    if(sr!=null)
    {
        sr.destroy();
    }
    

    or:

    try{
            sr.destroy();
    } 
     catch (Exception e)
    {
     Log.e(TAG,"Exception:"+e.toString());
    }
    
    0 讨论(0)
提交回复
热议问题