improve lifecycle
This commit is contained in:
		| @ -104,27 +104,37 @@ class SttDialog : DialogFragment() { | ||||
|                         putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true) | ||||
|                         putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true) | ||||
|                     } | ||||
|                     stt = SpeechRecognizer.createSpeechRecognizer(activity).apply { | ||||
|                         setRecognitionListener(SttListener()) | ||||
|                         try { | ||||
|                             stopListening() | ||||
|                             startListening(sttIntent) | ||||
|                         } catch (e: ActivityNotFoundException) { | ||||
|                             sttEnabled = false | ||||
|                             dismiss() | ||||
|                             showPopUp(R.string.STT_unavailable) | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     }.create()!! | ||||
|  | ||||
|     override fun onStop() { | ||||
|     override fun onResume() { | ||||
|         super.onResume() | ||||
|  | ||||
|         matchActivity?.apply { | ||||
|             matchModel?.apply { | ||||
|                 stt?.destroy() | ||||
|                 stt = SpeechRecognizer.createSpeechRecognizer(activity).apply { | ||||
|                     setRecognitionListener(SttListener()) | ||||
|                     try { | ||||
|                         stopListening() | ||||
|                         startListening(sttIntent) | ||||
|                     } catch (e: ActivityNotFoundException) { | ||||
|                         sttEnabled = false | ||||
|                         dismiss() | ||||
|                         showPopUp(R.string.STT_unavailable) | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     override fun onPause() { | ||||
|         unMuteAudio() | ||||
|         stt?.stopListening() | ||||
|         stt?.destroy() | ||||
|         super.onStop() | ||||
|         super.onPause() | ||||
|     } | ||||
|  | ||||
|     @Suppress("DEPRECATION") | ||||
|  | ||||
| @ -28,7 +28,6 @@ class VictoryActivity : AppCompatActivity() { | ||||
|         previousMatch = getPreferences(Context.MODE_PRIVATE) | ||||
|         initVictoryModel() | ||||
|         updateUI() | ||||
|         saveScore() | ||||
|     } | ||||
|  | ||||
|     fun initVictoryModel() { | ||||
| @ -76,7 +75,7 @@ class VictoryActivity : AppCompatActivity() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     fun saveScore() { | ||||
|     override fun onStop() { | ||||
|         victoryModel?.apply { | ||||
|             previousMatch?.edit()?.apply { | ||||
|                 putString( | ||||
| @ -92,6 +91,7 @@ class VictoryActivity : AppCompatActivity() { | ||||
|                 commit() | ||||
|             } | ||||
|         } | ||||
|         super.onStop() | ||||
|     } | ||||
|  | ||||
|     fun newMatch(view: View) { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user