Android Base Activity的onActivityResult()结果需要来自子活动

时间:2015-02-10 12:50:57

标签: java android android-activity

我的基本活动代码 -

public abstract class SpeechToTextActivity extends Activity {

private final int REQ_CODE_SPEECH_INPUT = 100;



/**
 * Showing google speech input dialog
 * */
public void promptSpeechInput() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            getString(R.string.speech_prompt));
    try {
        startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
    } catch (ActivityNotFoundException a) {
        Toast.makeText(getApplicationContext(),
                getString(R.string.speech_not_supported),
                Toast.LENGTH_SHORT).show();
    }
}

/**
 * Receiving speech input
 * */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case REQ_CODE_SPEECH_INPUT: {
        if (resultCode == RESULT_OK && null != data) {

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


        }
        break;
    }

    }
}

}

现在我需要另一个扩展SpeechToTextActivity的子活动的onActivityResult()结果。

请帮帮我。

1 个答案:

答案 0 :(得分:1)

覆盖子项中的onActivityResult,并检索结果。代码是一样的。如果孩子负责管理数据,您应该从父项中删除案例并将代码放在派生类中