1

我正在开发一个 android 应用程序,点击运行后,我解锁 AVD 并单击菜单加载我的应用程序,我立即收到以下消息:The application Pico TTS (process com.svox..pico) has stopped unexpectedly. Please try again

这是我的AndroidManifest.xml

    <application android:icon="@drawable/icon" android:label="@string/app_name" android:allowBackup="true">
        <activity android:name=".MPActivity"
                  android:label="@string/app_name"
                  >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

这些是来自我的 logcat 的消息:

10-09 13:01:14.796: I/TextToSpeech.java(1861): initTts() successfully bound to service
10-09 13:01:16.916: E/ActivityThread(1861): Activity com.kelamrsan.MPActivity has leaked ServiceConnection android.speech.tts.TextToSpeech$1@4051d710 that was originally bound here
10-09 13:01:16.916: E/ActivityThread(1861): android.app.ServiceConnectionLeaked: Activity com.kelamrsan.MPActivity has leaked ServiceConnection android.speech.tts.TextToSpeech$1@4051d710 that was originally bound here
10-09 13:01:16.916: E/ActivityThread(1861):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:938)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:833)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.speech.tts.TextToSpeech.initTts(TextToSpeech.java:467)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.speech.tts.TextToSpeech.<init>(TextToSpeech.java:433)
10-09 13:01:16.916: E/ActivityThread(1861):     at com.kelamrsan.MPActivity.onCreate(MPActivity.java:47)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.os.Looper.loop(Looper.java:130)
10-09 13:01:16.916: E/ActivityThread(1861):     at android.app.ActivityThread.main(ActivityThread.java:3683)
10-09 13:01:16.916: E/ActivityThread(1861):     at java.lang.reflect.Method.invokeNative(Native Method)
10-09 13:01:16.916: E/ActivityThread(1861):     at java.lang.reflect.Method.invoke(Method.java:507)
10-09 13:01:16.916: E/ActivityThread(1861):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-09 13:01:16.916: E/ActivityThread(1861):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-09 13:01:16.916: E/ActivityThread(1861):     at dalvik.system.NativeStart.main(Native Method)

这是我的onCreate

 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     Button buttonLoadImage = (Button)findViewById(R.id.loadimage);

 textView    = (TextView) findViewById(R.id.textView);
 textViewCol = (TextView) findViewById(R.id.textViewColor);
 targetImage = (ImageView) findViewById(R.id.targetimage);
 textViewVal = (TextView) findViewById(R.id.textViewValue);

  mTts = new TextToSpeech(this, new OnInitListener() {      
    @Override
    public void onInit(int status) {
    TTSInitialized = true;
    }
  });

  Intent installIntent = new Intent();
  installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
  startActivity(installIntent);

 buttonLoadImage.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new   Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  startActivityForResult(intent, 0);
 }});

}

那你觉得问题出在哪里?!

4

2 回答 2

4

看起来您正在创建将当前活动作为上下文传递的 TTS 对象。

然后您立即开始一个新活动(我假设不要关闭您的 OnPause 中的 TTS 对象)

这会使系统抱怨,因为您有一个与现在非活动活动相关联的活动服务。

您应该使用活动生命周期回调来设置和拆除任何依赖于活动的服务。

例如在 OnResume() 中设置您的 TTS 对象并在 OnPause() 中关闭它

于 2013-10-09T13:44:59.657 回答
0

听起来好像您有一个广播侦听器,它被加载一次,然后没有按预期释放。如果是这种情况,那么您需要分析覆盖该广播接收器的应用程序的生命周期,并确保它在之前的活动启动时关闭。如果需要,您甚至可以在创建广播时将其包围在 try catch 中并且什么也不做。因为Android会为你处理冲突,如果一切都失败了,就会默默地失败;显然,找到合适的收盘价是理想的。

这就是我可以从提供的内容中推断出的全部内容。

于 2013-10-09T13:32:57.453 回答