Search code examples
androidback-buttononbackpressedback-button-control

how to change behaviour back button in android


My app includes tts and stt. My app works by voice command.

So, I want to use the back button. When the user click back button, the app should go to the first step, but it didn't.

My code;

public class SpeechActivity extends FragmentActivity implements Const {

    protected PowerManager.WakeLock mWakeLock; 
    private SpeechRecognizer mSpeechRecognizer; 
    private Intent mSpeechRecognizerIntent;
    private SpeechRecognitionListener srListener;
    private Vocalizer vocalizer;
    private Object lastTtsContext = null;
.......
@Override
    public void onBackPressed() {

        speakToDisabled(Const.COMMAND_WARNING_MESSAGE); 
        super.onBackPressed();
        try {
            mSpeechRecognizer.wait();
        } catch (InterruptedException e) {
            speakToDisabled(Const.COMMAND_BYE);
        }
    }

Solution

  • Delete or comment this line, because it finish your current activity.

    super.onBackPressed();