Создал клавиатуру ,в клаве присутствует голосовой ввод,при нажатии перехожу в активити ,после чего сказав какое то слово активити закрывается.Проблема заключается в том что при закрытии активити , текста не видно ,но при повторном нажатии на голосовой ввод отображаетьсся текст сказанный ранее.И так повторяется постоянно опять открыл активити сказал ,закрыл текста нет ,нажал на голосовой ввод текст предыдущий появился . Как это исправить ?
public void onKey(int pc, int[] key) {
ic = getCurrentInputConnection();
al.clear();
//cv.clear();
switch (pc) {
case 45:
Speech.i=false;
Speech.ic=ic;
Intent intent = new Intent(getApplicationContext(),Speech.class);
intent.setFlags(intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
getCurrentInputConnection().commitText(Speech.spoken, 1);
}
public class Speech extends Activity {
static ArrayList<String> results;
static float[] confidence;
public static String spoken;
public static boolean i = true;
public static InputConnection ic;
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
// Specify free form input
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
"or forever hold your peace");
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.ENGLISH);
startActivityForResult(intent, 5);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 5 && resultCode == RESULT_OK) {
results = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String confidenceExtra = RecognizerIntent.EXTRA_CONFIDENCE_SCORES;
confidence = data.getFloatArrayExtra(confidenceExtra);
// TODO Do something with the recognized voice strings
}
spoken = null;
spoken=getWord();
Main.ic.commitText(spoken, 1);
//Main m =new Main();
//m.onKey(28, key)
//broadcastIntent();
finish();
}
public String getWord() {
float max = confidence[0];
int j = 0;
for (int i = 0; i < results.size(); i++) {
if (max < confidence[i]) {
j = i;
max = confidence[i];
}
}
//Log.i("main", "" + spoken);
i = true;
spoken=results.get(j);
Log.i("main", "" + spoken);
return spoken;
}
/* public void broadcastIntent()
{
Intent intent =new Intent();
intent.setAction("ttsdone");
sendBroadcast(intent);
}*/
}