Search code examples
androidtext-to-speech

Android Text to speech select dialog only once


I am using the TTS in my Activity. I Want the tts dialog appear only one time.

enter image description here

  • For example: In the screen shoot suppose i choose the pico tts. when i open this activity next time. I don't want it will open next time

Solution

  • You could use a sharedpreference. Suppose you define a boolean that on picking the TTS you want to use is set to true and saved to the shared preferences. Next time you run the app you should check the value of said boolean and only launch the dialog if it is false.

    Example:

    private SharedPreferences preferences;
    private String PREFS_NAME = "com.example.stackoverflow";
    private String PREFS_CHECK = "com.example.stackoverflow.check";
    private Boolean check;
    
    preferences = this.getSharedPreferences(PREFS_NAME,MODE_PRIVATE); 
    check = preferences.getInt(PREFS_CHECK_STATS,false);
    
    if(check){
    .
    .
    .
    }else{
    .
    .
    .
    preferences.edit().putBoolean(PREFS_CHECK,true).commit(); //Here you set the value.
    }