无法杀死android中的当前进程

时间:2012-03-01 16:59:21

标签: android

我有一个应用程序,我需要在应用程序询问用户确认之后终止应用程序。我正在使用以下代码段。

    while(tts.isSpeaking());

tts.speak("Quitting application",TextToSpeech.QUEUE_FLUSH, null);

    while(tts.isSpeaking());
    tts.shutdown();
    int pid = android.os.Process.myPid();
    android.os.Process.killProcess(pid);

tts引擎说“退出应用程序”。屏幕空白一段时间。然后,应用程序重新启动。我没有得到我错的地方。

我也试过了System.exit(0)。仍然发生同样的事情。告诉我正确的方法。我在使用tts时也遇到了一些问题。在应用程序运行期间,我无法同步说话和许多事件。我怎样才能克服这个问题?

2 个答案:

答案 0 :(得分:0)

你不应该在while循环周围有{}吗?例如

    while(tts.isSpeaking()) {
    tts.shutdown();
    int pid = android.os.Process.myPid();
    android.os.Process.killProcess(pid);
    }

答案 1 :(得分:0)

dude try finish()它将完成活动并指定括号。不要在里面使用 int pid = android.os.Process.myPid(); android.os.Process.killProcess(pid);而要杀死整个应用程序使用
<强>记住
             Intent intent = new Intent(Intent.ACTION_MAIN);              intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);              intent.addCategory(Intent.CATEGORY_HOME);               startActivity(intent);