gpt4 book ai didi

java - fragment 和文本转语音以及幻灯片菜单

转载 作者:太空宇宙 更新时间:2023-11-04 14:10:33 26 4
gpt4 key购买 nike

我想知道如何在使用 Fragment 时关闭 TTS。

当我尝试返回到上一个 fragment 时,出现这些错误:

02-07 00:25:20.972: E/ActivityThread(2095): Activity com.PishgamanIt.ETPUP.MainActivity has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@b1322460 that was originally bound here
02-07 00:25:20.972: E/ActivityThread(2095): android.app.ServiceConnectionLeaked: Activity com.PishgamanIt.ETPUP.MainActivity has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@b1322460 that was originally bound here
02-07 00:25:20.972: E/ActivityThread(2095): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:974)
02-07 00:25:20.972: E/ActivityThread(2095): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:868)
02-07 00:25:20.972: E/ActivityThread(2095): at android.app.ContextImpl.bindServiceAsUser(ContextImpl.java:1452)
02-07 00:25:20.972: E/ActivityThread(2095): at android.app.ContextImpl.bindService(ContextImpl.java:1440)
02-07 00:25:20.972: E/ActivityThread(2095): at android.content.ContextWrapper.bindService(ContextWrapper.java:496)
02-07 00:25:20.972: E/ActivityThread(2095): at android.speech.tts.TextToSpeech.connectToEngine(TextToSpeech.java:685)
02-07 00:25:20.972: E/ActivityThread(2095): at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:655)
02-07 00:25:20.972: E/ActivityThread(2095): at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:608)
02-07 00:25:20.972: E/ActivityThread(2095): at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:582)
02-07 00:25:20.972: E/ActivityThread(2095): at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:567)
02-07 00:25:20.972: E/ActivityThread(2095): at com.PishgamanIt.ETPUP.CustomListViewAddapter.getView(CustomListViewAddapter.java:113)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.AbsListView.obtainView(AbsListView.java:2177)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.ListView.makeAndAddView(ListView.java:1840)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.ListView.fillDown(ListView.java:675)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.ListView.fillFromTop(ListView.java:736)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.ListView.layoutChildren(ListView.java:1655)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.AbsListView.onLayout(AbsListView.java:2012)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:890)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.Choreographer.doFrame(Choreographer.java:532)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
02-07 00:25:20.972: E/ActivityThread(2095): at android.os.Handler.handleCallback(Handler.java:730)
02-07 00:25:20.972: E/ActivityThread(2095): at android.os.Handler.dispatchMessage(Handler.java:92)
02-07 00:25:20.972: E/ActivityThread(2095): at android.os.Looper.loop(Looper.java:137)
02-07 00:25:20.972: E/ActivityThread(2095): at android.app.ActivityThread.main(ActivityThread.java:5103)
02-07 00:25:20.972: E/ActivityThread(2095): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 00:25:20.972: E/ActivityThread(2095): at java.lang.reflect.Method.invoke(Method.java:525)
02-07 00:25:20.972: E/ActivityThread(2095): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-07 00:25:20.972: E/ActivityThread(2095): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-07 00:25:20.972: E/ActivityThread(2095): at dalvik.system.NativeStart.main(Native Method)
02-07 00:25:20.972: E/ActivityThread(2095): Activity com.PishgamanIt.ETPUP.MainActivity has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@b131d010 that was originally bound here
02-07 00:25:20.972: E/ActivityThread(2095): android.app.ServiceConnectionLeaked: Activity com.PishgamanIt.ETPUP.MainActivity has leaked ServiceConnection android.speech.tts.TextToSpeech$Connection@b131d010 that was originally bound here
02-07 00:25:20.972: E/ActivityThread(2095): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:974)
02-07 00:25:20.972: E/ActivityThread(2095): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:868)
02-07 00:25:20.972: E/ActivityThread(2095): at android.app.ContextImpl.bindServiceAsUser(ContextImpl.java:1452)
02-07 00:25:20.972: E/ActivityThread(2095): at android.app.ContextImpl.bindService(ContextImpl.java:1440)
02-07 00:25:20.972: E/ActivityThread(2095): at android.content.ContextWrapper.bindService(ContextWrapper.java:496)
02-07 00:25:20.972: E/ActivityThread(2095): at android.speech.tts.TextToSpeech.connectToEngine(TextToSpeech.java:685)
02-07 00:25:20.972: E/ActivityThread(2095): at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:655)
02-07 00:25:20.972: E/ActivityThread(2095): at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:608)
02-07 00:25:20.972: E/ActivityThread(2095): at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:582)
02-07 00:25:20.972: E/ActivityThread(2095): at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:567)
02-07 00:25:20.972: E/ActivityThread(2095): at com.PishgamanIt.ETPUP.CustomListViewAddapter.getView(CustomListViewAddapter.java:113)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.AbsListView.obtainView(AbsListView.java:2177)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.ListView.makeAndAddView(ListView.java:1840)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.ListView.fillDown(ListView.java:675)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.ListView.fillFromTop(ListView.java:736)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.ListView.layoutChildren(ListView.java:1655)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.AbsListView.onLayout(AbsListView.java:2012)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:890)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:349)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.View.layout(View.java:14289)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewGroup.layout(ViewGroup.java:4562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.Choreographer.doFrame(Choreographer.java:532)
02-07 00:25:20.972: E/ActivityThread(2095): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
02-07 00:25:20.972: E/ActivityThread(2095): at android.os.Handler.handleCallback(Handler.java:730)
02-07 00:25:20.972: E/ActivityThread(2095): at android.os.Handler.dispatchMessage(Handler.java:92)
02-07 00:25:20.972: E/ActivityThread(2095): at android.os.Looper.loop(Looper.java:137)
02-07 00:25:20.972: E/ActivityThread(2095): at android.app.ActivityThread.main(ActivityThread.java:5103)
02-07 00:25:20.972: E/ActivityThread(2095): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 00:25:20.972: E/ActivityThread(2095): at java.lang.reflect.Method.invoke(Method.java:525)
02-07 00:25:20.972: E/ActivityThread(2095): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-07 00:25:20.972: E/ActivityThread(2095): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-07 00:25:20.972: E/ActivityThread(2095): at dalvik.system.NativeStart.main(Native Method)

我尝试将其放入所有 fragment 和 Activity 中

@Override
public void onDestroyView() {
// TODO Auto-generated method stub
super.onDestroyView();
CustomListViewAddapter.tts.shutdown();
}

@Override
public void onPause() {
// TODO Auto-generated method stub
super.onDestroyView();
CustomListViewAddapter.tts.shutdown();
}

但是每当我尝试使用顶部幻灯片菜单中的 < 返回主页时,我仍然会收到这些错误。

最佳答案

首先,感谢@corsai992。

其次,我将 tts 添加到我的 CustomListViewAddapter 承包商中,并且每当我需要 CustomListViewAddapter 时,我都会创建 tts 并将其传递给该类。

编码愉快:)

关于java - fragment 和文本转语音以及幻灯片菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28379297/

26 4 0