- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用在语音识别命令后使用文字转语音。我早些时候让它工作没有错误,但现在它给了我一个服务连接泄漏错误,并且不会启动 Activity 。我已经在错误所在的位置包含了我的 LogCat 和 Java 文件。
08-06 08:54:50.090: E/ActivityThread(2871): android.app.ServiceConnectionLeaked: Activity com.example.com.proto1.menu has leaked ServiceConnection android.speech.tts.TextToSpeech$1@408b10d8 that was originally bound here
08-06 08:54:50.090: E/ActivityThread(2871): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:932)
08-06 08:54:50.090: E/ActivityThread(2871): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:827)
08-06 08:54:50.090: E/ActivityThread(2871): at android.app.ContextImpl.bindService(ContextImpl.java:1109)
08-06 08:54:50.090: E/ActivityThread(2871): at android.content.ContextWrapper.bindService(ContextWrapper.java:370)
08-06 08:54:50.090: E/ActivityThread(2871): at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:517)
08-06 08:54:50.090: E/ActivityThread(2871): at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:483)
08-06 08:54:50.090: E/ActivityThread(2871): at com.example.com.proto1.menu.onActivityResult(menu.java:250)
08-06 08:54:50.090: E/ActivityThread(2871): at android.app.Activity.dispatchActivityResult(Activity.java:4581)
08-06 08:54:50.090: E/ActivityThread(2871): at android.app.ActivityThread.deliverResults(ActivityThread.java:2817)
08-06 08:54:50.090: E/ActivityThread(2871): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2864)
08-06 08:54:50.090: E/ActivityThread(2871): at android.app.ActivityThread.access$1000(ActivityThread.java:122)
08-06 08:54:50.090: E/ActivityThread(2871): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1057)
08-06 08:54:50.090: E/ActivityThread(2871): at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 08:54:50.090: E/ActivityThread(2871): at android.os.Looper.loop(Looper.java:132)
08-06 08:54:50.090: E/ActivityThread(2871): at android.app.ActivityThread.main(ActivityThread.java:4126)
08-06 08:54:50.090: E/ActivityThread(2871): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 08:54:50.090: E/ActivityThread(2871): at java.lang.reflect.Method.invoke(Method.java:491)
08-06 08:54:50.090: E/ActivityThread(2871): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
08-06 08:54:50.090: E/ActivityThread(2871): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
08-06 08:54:50.090: E/ActivityThread(2871): at dalvik.system.NativeStart.main(Native Method)
package com.example.com.proto1;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.speech.RecognizerIntent;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import android.speech.tts.TextToSpeech;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@SuppressWarnings("unused")
public class menu extends Activity implements TextToSpeech.OnInitListener,
OnClickListener {
// defined
TextToSpeech mTts;
public static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;
// remember to include a listview on the xml or the voice recognition code
// will not work
public ListView mList;
// TTS object
Button speakButton, infoButton, voiceButton, talkButton;
// TTS object
public TextToSpeech myTTS;
// status check code
public int MY_DATA_CHECK_CODE = 0;
@Override
protected void onCreate(Bundle aboutmenu) {
super.onCreate(aboutmenu);
setContentView(R.layout.mainx);
SpeakingAndroid speak = new SpeakingAndroid();
VoiceRecognition voiceinput = new VoiceRecognition();
// get a reference to the button element listed in the XML layout
speakButton = (Button) findViewById(R.id.btn_speak);
infoButton = (Button) findViewById(R.id.aboutbutton);
voiceButton = (Button) findViewById(R.id.voicebutton);
talkButton = (Button) findViewById(R.id.talk);
// listen for clicks
infoButton.setOnClickListener(this);
speakButton.setOnClickListener(this);
talkButton.setOnClickListener(this);
// check for TTS data
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
// calling method
voiceinputbuttons();
// Check to see if a recognition activity is present
// if running on AVD virtual device it will give this message. The mic
// required only works on an actual android device//
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() != 0) {
voiceButton.setOnClickListener(this);
} else {
voiceButton.setEnabled(false);
voiceButton.setText("Recognizer not present");
}
}
// setup TTS
public void onInit(int initStatus) {
// check for successful instantiation
// returns a fail statement if speech doesn't work
if (initStatus == TextToSpeech.SUCCESS) {
if (myTTS.isLanguageAvailable(Locale.US) == TextToSpeech.LANG_AVAILABLE)
myTTS.setLanguage(Locale.US);
} else if (initStatus == TextToSpeech.ERROR) {
Toast.makeText(this, "Sorry! Text To Speech failed...",
Toast.LENGTH_LONG).show();
}
}
public void informationmenu() {
speakWords("information screen");
startActivity(new Intent("android.intent.action.INFOSCREEN"));
}
public void voicemenu() {
speakWords("voice recognition menu");
startActivity(new Intent("android.intent.action.RECOGNITIONMENU"));
}
public void mainmenu() {
speakWords("main menu");
startActivity(new Intent("android.intent.action.MENU"));
}
// creating method
public void voiceinputbuttons() {
speakButton = (Button) findViewById(R.id.btn_speak);
mList = (ListView) findViewById(R.id.list);
}
// respond to button clicks
public void onClick(View v) {
switch (v.getId()) {
// use switch case so each button does a different thing
// accurately(similar to an if statement)
case R.id.btn_speak:
String words1 = speakButton.getText().toString();
// speakwords(xxxx); is the piece of code that actually calls the
// text to speech
speakWords(words1);
Intent voiceIntent = new Intent("ANDROID_NET");
startActivity(voiceIntent);
break;
case R.id.aboutbutton:
String words2 = infoButton.getText().toString();
speakWords(words2);
Intent infoIntent = new Intent("android.intent.action.INFOSCREEN");
startActivity(infoIntent);
break;
case R.id.voicebutton:
speakWords("Speak Now");
startVoiceRecognitionActivity(); // call for voice recognition
// activity
break;
case R.id.talk:
speakWords("This is the main menu.");
break;
}
}
// speak the user text
// setting up the speakWords code
public void speakWords(String speech) {
// speak straight away
myTTS.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
}
/**
* Fire an intent to start the speech recognition activity.
*/
public void startVoiceRecognitionActivity() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
"Speech recognition demo");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST_CODE);
}
/**
* Handle the results from the recognition activity.
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST_CODE
&& resultCode == RESULT_OK) {
// Fill the list view with the strings the recognizer thought it
// could have heard
ArrayList<String> matches = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
mList.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, matches));
// matches is the result of voice input. It is a list of what the
// user possibly said.
// Using an if statement for the keyword you want to use allows the
// use of any activity if keywords match
// it is possible to set up multiple keywords to use the same
// activity so more than one word will allow the user
// to use the activity (makes it so the user doesn't have to
// memorize words from a list)
// to use an activity from the voice input information simply use
// the following format;
// if (matches.contains("keyword here") { startActivity(new
// Intent("name.of.manifest.ACTIVITY")
if (matches.contains("information")) {
informationmenu();
}
if (matches.contains("info screen")) {
informationmenu();
}
if (matches.contains("info")) {
informationmenu();
}
if (matches.contains("about")) {
informationmenu();
}
if (matches.contains("home")) {
mainmenu();
}
if (matches.contains("menu")) {
mainmenu();
}
if (matches.contains("home screen")) {
mainmenu();
}
if (matches.contains("speak")) {
startActivity(new Intent("android.intent.action.SPEAK"));
}
if (matches.contains("close")) {
finish();
}
if (matches.contains("stop")) {
finish();
}
if (matches.contains("finish")) {
finish();
}
if (matches.contains("voice")) {
voicemenu();
}
if (matches.contains("recognition")) {
voicemenu();
}
if (matches.contains("voice recognition")) {
voicemenu();
}
}
// still in the onActivityResult: This is for the text to speech part
if (requestCode == MY_DATA_CHECK_CODE) {
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
// the user has the necessary data - create the TTS
myTTS = new TextToSpeech(this, this);
} else {
// no data - install it now
Intent installTTSIntent = new Intent();
installTTSIntent
.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installTTSIntent);
}
}
super.onActivityResult(requestCode, resultCode, data);
}
}
最佳答案
在 Activity 的 onDestroy()
方法中使用
ttsObj.shutdown();
关于java - Text-To-Speech 上的服务连接泄露,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11828998/
大家晚上好! 在当前的项目中,我遇到了相当令人担忧的内存泄漏,但我似乎无法修复它。 我让应用程序在标准使用情况下运行过夜,当我在 8 小时后醒来时,它消耗了约 750MB 内存,而它一开始的内存约为
class MyViewController: UIViewController { @IBOutlet weak var webView: UIWebView? override
我的 sql 处理程序有问题 A SQLiteConnection object for database '/data/data/.../databases/queueManager' was le
我在引用 block 本身内的“NSBlockOperation”时遇到麻烦。我需要检查操作是否被取消,并且似乎在启用 ARC 的项目中运行时,对“searchOperation”的任何访问都会泄漏。
public class ProgressCircleActivity extends AppCompatActivity { private ProgressDialog progressB
Activity 泄漏是我可以为当前问题想到的最具体的术语。如果有其他情况,请指正。 场景:我创建了一个简单的 Android 测试应用程序来解决我的问题。我有一个 Activity ,一个添加到 f
我正在尝试创建身份验证系统,如果设备关闭 (SCREEN_OFF) 超过 INTERVAL,该系统会弹出登录窗口。 我已经注册了一个 BroadcastReceiver 来监听可启动 Activity
我想知道如果生产 key 被泄露需要采取哪些步骤。幸运的是,情况并非如此,但还是很高兴知道。 特别是,如果简单地将旧 key 交换为新生成的 key ,会发生什么情况?由于它用于生成哈希,是否会破坏整
我正在使用 Leak Canary 来跟踪内存泄漏,它说以下内容被泄漏: static hk.o references ht.a leaks MainActivity instance hk.o 和
-(NSDate *)dateFromDate:(NSDate *)inDate withNewTime:(NSDateComponents *)inTimeComponents { NSCalend
当我使用 AudioToolBox 播放音乐时,内存泄漏严重。 AVAudioPlayer *newMusicPlayer = [[AVAudioPlayer alloc] initWithData:
我使用 OpenAL 在我的应用程序中播放声音。当我使用 Instruments 工具测试它时,它发现了泄漏: LeakedObject = GeneralBlock-512 大小 = 512 字节
我需要捕获桌面图像并处理其 RGB 数据,我正在使用 Quartz API 来执行相同的操作, 我面临的问题是内存使用率高, 请引用函数, 在这里编辑,该函数是通过 pThread 调用的;像这样的东
我的 Android 应用程序中有一个 MapActivity,它使用 osmdroid(Open Street Map for Android 库)显示 map 。 当我在此 MapActivity
我在 fragment 中使用 AdMob。有时我会看到以下堆栈 10-23 14:27:38.916: E/ActivityThread(21250): Activity com.applegrew
我正在使用以下方式访问我的 API key ;这似乎是 recommended way ;但是当我将我的应用程序上传到 Play 管理中心时,运行预发布报告时出现严重错误。它说“泄漏的 GCP API
一家 3rd 方安全咨询公司在我们的 Angular SPA/ASP.NET WebAPI 应用程序中发现了 区域下的风险。信息公开 ,我们被告知要解决。 风险是由于 Angular 应用程序的性质,
在 Android 中,当读取 MIFARE Classic 卡时,使用 MifareClassic.authenticateSectorWithKeyA(或 authenticateSectorWi
加载谷歌地图时在分析器中获取泄漏。我根据谷歌的示例代码创建了一个非常简单的 View Controller ,我发现我在加载 map 时遇到了泄漏。我相信泄漏是在 SDK 本身。有没有人遇到过这个问题
我是一名优秀的程序员,十分优秀!