Jump to content

La rotation de l'écran relance onInit()


Guest hardrocky

Recommended Posts

Guest hardrocky

Bonjour à tous.

Voilà un bout de code :


public void onInit(int status) { // Synthèse
       if (status == TextToSpeech.SUCCESS) {
        int result;
        String langue = Locale.getDefault().getLanguage(); // Selon la langue
    if (langue.equalsIgnoreCase("fr")) {
    result = tts.setLanguage(Locale.FRENCH);
    }
    else {
    result = tts.setLanguage(Locale.ENGLISH);
    }

           if (result == TextToSpeech.LANG_MISSING_DATA
                   || result == TextToSpeech.LANG_NOT_SUPPORTED) {

            AlertDialog.Builder builder = new AlertDialog.Builder(this);

               builder.setTitle(R.string.dialogttstitle);
               builder.setMessage(R.string.dialogttstext);

               builder.setPositiveButton(R.string.dialogttsyes, new DialogInterface.onclickListener() {
                @Override
                   public void onclick(DialogInterface dialog, int which) {
                       // ACTIONS
                   }
               });
               builder.setNegativeButton(R.string.dialogttsno, new DialogInterface.onclickListener() {
                   @Override
                   public void onclick(DialogInterface dialog, int which) {
                    // ACTIONS
                   }
               });
               AlertDialog alert = builder.create();
               alert.show();
           }
       }

Ce code affiche au lancement de l'application une dialogbox si une langue n'est pas installée (pour la synthèse vocale).

Or, cette dialogbox se re-affiche si l'on tourne l'écran. Comment empêcher cela ?

Merci d'avance

Link to comment
Share on other sites

Par défaut, l'activité se relance au changement d'orientation, d'où ton problème ==>

dans le manifest.xml :

  • soit tu fige l'orientation de l'écran,
  • soit tu spécifies que tu prends en charge les changements d'orientation et tu implémentes le onXxx correspondant.

Link to comment
Share on other sites

Guest hardrocky

Ta première option ne me convient pas. J'ai plutot fait la deuxième, avec une variable static qui vaut 0 et 1 si la dialogbox a déjà été affichée.

Je fais un if avec la variable pour voir si la dialogbox a été lancée et si ce n'est pas le cas, je l'affiche.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...