2011-04-27 3 views
1

내 mainActivity는 사용자가 PreferenceActivity를 실행하기 위해 설정 버튼을 누를 때까지 시작시 Tab2Activity를 실행하지 않기 때문에 불필요한 부울 결과를 피하기 위해 먼저 audioStatus 부울 값을 확인해야하지만이 단계 후에 나는 kinna를 잃어 버렸습니다. CheckBoxPreference의 버그로 인해 ...CheckBoxPreference의 버그를 해결하는 방법 android의 기본값은 무엇입니까?

이제 로직 비교를 통해 Tab2Activity로 이동하지 않고도 오디오를 얻는 방법을 모르겠습니다. 여기에 내가 직면 한 주요 문제는 아직 바람직한 결과를 얻고있는 논리와 함께 일하고있다.

나는 java/android에서 새로운 것이며, 자동차 블랙 박스 앱을 만들고있다. 누군가 나를 도울 수있다 ... 감사합니다.

내 mainActivity 파일

if(Tab2Activity.audioPref == false) 
    audioStatus = false;  
else 
    audioStatus = Tab2Activity.audioPref; 

if(audioStatus == false) 
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); 

if(audioStatus == false) 
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); 

내 Tab2Activity.java 파일

public static boolean audioPref; 
    public static String timeIntervalPref; 

    public void getPrefs() { 
     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); 

     audioPref = prefs.getBoolean("AudioPref", true);//Suppose to produce "false" isn't it? 
     timeIntervalPref = prefs.getString("TimeIntervalPref", "60000"); 
    } 
} 

내 xml 파일

<CheckBoxPreference 
       android:title="Audio" 
       android:defaultValue="True" 
       android:summary="Select w/o Audio when Recording" 
       android:key="AudioPref" /> 

답변

0

설정을 SharedPreferences에 저장 한 다음 Tab2Activity의 공개 부울 상태에 의존하지 않고 설정을 읽습니다. 사용

http://developer.android.com/reference/android/content/SharedPreferences.html

예 : http://saigeethamn.blogspot.com/2009/10/shared-preferences-android-developer.html

편집 : 나는 당신이 tab2activity에서 환경 설정을 얻으려고 노력하는 이유를 알고하지 않습니다. 왜 당신은 mainActivity에서 다음을 수행하지 않을 : 당신은 '거짓'에 대한 기본 공유 환경 설정 값을 설정하려고 할 때 연결

SharedPreferences prefs=PreferenceManager.getDefaultSharedreferences(getBaseContext()); 
audioStatus=prefs.getBoolean("AudioPref",true); // (only use true if you want the default to be true if the value has not yet been set, otherwise you should be doing ("AudioPref",false)) 

if(!audioStatus) 
{ 
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); 
} 

버그가 문제에 대해 설명합니다. 그 값을 기본값으로 사용하려면 getBoolean (string, defValue)을 사용하여 값을 검색 할 때 기본값으로 "false"를 사용하십시오.

+0

여기 내 문제는 CheckBoxPreference가 두 가지 상태 true/false로만되어 있습니다. 당신이 저에게 준 블로그에서 다른 종류의 환경 설정에 대해서만 이야기합니다 ... 그리고 CheckBoxPreference는 http://code.google.com/p/android/issues/detail?id=6641 버그가있는 것 같습니다. 그래서 나는 여기에 내 상황에 대한 더 tengible 솔루션을 찾으려고 도움을 찾고 있습니다. – zack

+0

그냥 MainActivity에 무슨 뜻인지 알지만, CheckBoxPreference가 설정 버튼을 클릭하면 초기화되기 때문에 이렇게 할 수 없습니다. 내 Tab2Activity 초기화 .. 그 이유는 내가 처음/미리 기본값 또는 오디오 플레이어 "기록"강제로 강제로 ...하지만 지금은 혼란/어떻게이 문제를 해결해야 혼란 ... – zack

관련 문제