2013-12-14 4 views
1

Приложение для Android имеет основной Intent, где пользователь входит в систему. После этого он загружает еще один Intent с помощью кнопок со стрелками, некоторой меткой, индикатором выполнения и некоторыми входными компонентами, которые чередуются, пока пользователь нажимает кнопки, чтобы перейти к другим вопросам (a исследовательская форма). По каждому вопросу метки меняются, а некоторые компоненты скрываются, пока другие отображаются. Но если пользователь поворачивает устройство, типы Intent сбрасываются, потому что он возвращается к первому вопросу.Как предотвратить сброс настроек после поворота устройства?

Код, который принимает ко второму Intent является:

public void onClick(View v) 
    { 
     if ((!selectedFormCode.equalsIgnoreCase("")) && (!userCode.getText().toString().equals(""))) 
     { 
      Intent questionScreen = new Intent(); 
      questionScreen.setClassName("com.android.artemis", "com.android.artemis.QuestionScreen"); 

      func.ShowMessage("Aguarde,\nCarregando o Formulário..."); 

      // envia as configurações para a tela de entrevista 
      questionScreen.putExtra("formProperties", formProperties.toString()); 
      questionScreen.putExtra("selectedFormCode", selectedFormCode); 
      questionScreen.putExtra("selectedRegionCode", selectedRegionCode); 
      questionScreen.putExtra("selectedSubRegionCode", selectedSubRegionCode); 
      questionScreen.putExtra("selectedRegionLabel", selectedRegionLabel); 
      questionScreen.putExtra("selectedSubRegionLabel", selectedSubRegionLabel); 
      questionScreen.putExtra("userRegistrationCode", userCode.getText().toString()); 

      startForm.setEnabled(false); // evita que o usuário clique mais de uma vez 

      startActivity(questionScreen); 

      startForm.setEnabled(true); 
     } 
     else 
     { 
      func.ShowMessage("Complete todas as Informações antes de Continuar!"); 
     } 
    } 

Код, который срабатывает, когда второй Намерение нагрузки является:

 super.onAttachedToWindow(); 
     try { 
      // recebe informações vindas da tela inicial 
      selectedFormCode = getIntent().getStringExtra("selectedFormCode"); 
      selectedRegionCode = getIntent().getStringExtra("selectedRegionCode"); 
      selectedSubRegionCode = getIntent().getStringExtra("selectedSubRegionCode"); 
      selectedRegionLabel = getIntent().getStringExtra("selectedRegionLabel"); 
      selectedSubRegionLabel = getIntent().getStringExtra("selectedSubRegionLabel"); 
      userRegistrationCode = getIntent().getStringExtra("userRegistrationCode"); 
      formProperties = new JSONObject(getIntent().getStringExtra("formProperties")); 
      //ArrayList<JSONObject> formList; 
      //JSONObject mainData = new JSONObject(func.getTextAssetFile("forms.dat")); 
      //formList = func.getJSONArrayList(mainData.get("forms").toString()); 
      //formProperties = formList.get(func.getIndexFromObject(formList, selectedFormCode)); 

      // inicializa a tela 
      formLabel.setText(formProperties.get("l").toString()); // label   
      customEdit.clearFocus(); 
      // inicializa variáveis a serem usadas na entrevista 
      totalQuestion = (Integer) formProperties.get("total"); 
      questionAnswer = new String[totalQuestion]; 
      subQuestionAnswer = new String[totalQuestion]; 
      questionsData = formProperties.getJSONArray("questions"); 
      // recupera a informação de quantidade de entrevistas feitas deste formulário, por este entrevistador 
      SharedPreferences settings = getSharedPreferences(selectedFormCode, 0); 
      totalInterview = settings.getInt(userRegistrationCode, 0); 
      // inicia uma nova entrevista depois que configura a tela 
      startNewInterview(); 
/*   
      // Inicialização de uma sessão do dropbox para sincronização de arquivos de entrevistas 
      AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET); 
      AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE); 
      mDBApi = new DropboxAPI<AndroidAuthSession>(session); 
      // 
      SharedPreferences dbas = getSharedPreferences("SPM", 0); 
      AccessTokenPair access = new AccessTokenPair(dbas.getString("dropboxKey", ""),dbas.getString("dropboxSecret", "")); 
      mDBApi.getSession().setAccessTokenPair(access); 
      mDBApi.getSession().startAuthentication(this); 
*/   
     } 
     catch (JSONException e) 
     { 
      e.printStackTrace(); 
      func.ShowMessage("Não foi possível decodificar as propriedades do formulário de pesquisa. \nErro Fatal! \nLibere mais Memória!!"); 
     } 

    } 

и

public void startNewInterview() // inicializa uma nova entrevista 
{ 
    // reinicia a barra de progresso 
    currentQuestion = 1; 
    progressBar.setMax(totalQuestion); 
    progressBar.setProgress(currentQuestion); 
    // limpar as variáveis de respostas 
    for (int i = 0; i < totalQuestion; i++) 
    { 
     questionAnswer[i] = ""; 
     subQuestionAnswer[i] = ""; 
    } 
    // inicializar o relógio 
    func.startChronometer(); 
    startTime = func.getChronometerTime(); 
    // determinat o momento do início da entrevista 
    Date now = new Date();; 
    SimpleDateFormat formatTime = new SimpleDateFormat(dateMask); 
    interviewDate = formatTime.format(now); 
    formatTime = new SimpleDateFormat(hourMask); 
    interviewHour = formatTime.format(now); 
    // ir para a primeira questão 
    goQuestion(currentQuestion); 
} 

ответ

1

Добавьте это в ваш Manifest

<activity 
     android:name="MyActivity" 
     android:configChanges="orientation|keyboard|keyboardHidden" 
     android:screenOrientation="sensor" /> 
Смежные вопросы