startActivityForResult不会返回到android中的onActivityResult

时间:2014-05-09 11:16:33

标签: android android-intent

我第一次使用requestCode x调用startActivityForResult()时返回onActivityResult()。但是第二次在不同的requestCode的同一个活动中调用startActivityForResult()它不会返回到onActivityResult()而只是继续 用代码。

我尝试将此属性添加到清单并将活动

添加
android:noHistory

为什么它不会返回onActivityResult()?我如何解决它? 非常感谢, 利昂

编辑:这是我的代码

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == MY_DATA_CHECK_CODE) {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {      
            myTTS = new TextToSpeech(this, this);
        }
        else {
            Intent installTTSIntent = new Intent();
            installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installTTSIntent);
        }
     }
    else if(RESULT_SPEECH == requestCode)
    {
        if (resultCode == RESULT_OK && null != data) {

            ArrayList<String> text = data
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

            textFromSpeech = text.get(0);
        }
    }
}

    private void getTextFromSpeech()
{   
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

    try {
        startActivityForResult(intent, RESULT_SPEECH);
    } catch (ActivityNotFoundException a) {
        Toast t = Toast.makeText(getApplicationContext(),
                "Ops! Your device doesn't support Speech to Text",
                Toast.LENGTH_SHORT);
        t.show();
    }


}

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tts_);

    /*
     * New Intent purely for the purposes of checking the user data
     */
    Intent checkTTSIntent = new Intent();
    checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
}

0 个答案:

没有答案