2010-05-14 5 views
4

SampleSyncAdapter 자습서에서와 같이 AccountAuthenticator 항목을 사용하여 계정 유형을 만들었습니다. 나는 현재 계정 환경 설정 작업을 시도하고있다. 체크 박스 환경 설정이 정상적으로 똑같이 작동하지만 ListPreference는 다음과 같은 메시지가 전체 시스템을 충돌ListPreference에서 계정 환경 설정이 충돌 함

<?xml version="1.0" encoding="utf-8"?> 

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 
<PreferenceCategory android:title="@string/alum_settings_title"/> 

<CheckBoxPreference 
    android:key="sync_alum" 
    android:title="@string/sync_alum" 
    android:summaryOn="@string/sync_alum_check" 
    android:summaryOff="@string/sync_alum_nocheck"/> 

<ListPreference 
    android:key="sync_alum_since" 
    android:title="@string/alum_years" 
    android:entries="@array/years" 
    android:entryValues="@array/years" 
    android:dependency="sync_alum"/> 
</PreferenceScreen> 

:과 같이

내가 내 account-authenticator 및 account_preferences.xml에 선 android:accountPreferences="@xml/account_preferences"을 추가 한

보인다

05-14 22:32:16.794: ERROR/AndroidRuntime(63): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application 

EditTextPreference와 내가 만든 DialogPreference의 사용자 정의 하위 클래스에서 동일한 오류가 발생합니다.

+0

추 신. 다음은 전체 스택 추적입니다. 가독성을 유지하기 위해 원래 게시물에 넣지 않았습니다. http://gist.github.com/raw/401785/73141d95ebddab0fc67b6219c38701c8d3ac7051/gistfile1.txt – Sionide21

답변

-1

웃음 소리가 들리는 경우 PreferenceCategory을 누락 해보십시오. 어쨌든, 그것은 어떤 선호도를 감싸고 있지 않기 때문에 당신을 많이하지 않습니다. 이 문제가 의심 스럽지만 XML과 관련해서는 이상한 점이 있습니다.

그렇지 않으면 해당 예외가 "Android 버그"를 표시하므로 오류를 재생하는 프로젝트를 만들 수 있다면이 정보를 http://b.android.com에 게시하십시오.

+0

해당 카테고리 태그를 삭제해도 아무 것도 변경되지 않았습니다. 버그를 제출하기 전에 조금 더 살펴 보겠습니다. – Sionide21

+0

좋아, 나는 이것이 'PreferenceActivity'를 만들었고 동일한 XML 파일을 가리키는'addPreferencesFromResource'를 사용할 때 잘 동작하기 때문에 이것은 버그라고 생각합니다. – Sionide21

+0

Android 팀의 버그 또는 잘못된 디자인 일 수 있습니다. 그러나 그것이 스스로 문제를 해결하지 못한다고 말합니다. – petersaints

-1

아마 같은 배열을 사용하고 있기 때문입니까? entriesentryValues으로 사용 하시겠습니까?

는 다른 배열을하고

android:entries="@array/years" 
android:entryValues="@array/years_values" 
0

있음이 버그 것으로 보인다하려고 시도합니다. Google에 버그가 있습니다.

편집 및 목록 환경 설정에서 동일한 문제를 확인할 수 있습니다. 지금까지 CheckBox를 충돌없이 작동시킬 수 있습니다. 상태는 지속되지만 상태가 저장되는 위치는 알 수 없습니다.

1

나는 아주 똑같은 문제가있어 위에서 언급 한 것과 동일한 예외가 발생했습니다. Android 소스를 살펴본 후에는 대화 또는 새 창을 만들려는 모든 환경 설정에 해당되는 것으로 보입니다. 이것은 APPLICATION_WINDOW로 잘못 만들어진 것 같습니다.

문서의 AbstractAccountAuthenticator에서이 예는 클릭시 의도를 사용합니다.

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 
<PreferenceCategory android:title="@string/title_fmt" /> 
<PreferenceScreen 
    android:key="key1" 
    android:title="@string/key1_action" 
    android:summary="@string/key1_summary"> 
    <intent 
     android:action="key1.ACTION" 
     android:targetPackage="key1.package" 
     android:targetClass="key1.class" /> 
</PreferenceScreen> 

나는 의도가 계정 환경 설정에서 새 환경 활동을 시작하고 장소에 사용하지 않는 것입니다 생각합니다. 나쁜 점은 새로운 팝업을 허용 하자는 것입니다. 예외 :

10-01 09:33:36.935: ERROR/AndroidRuntime(52): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want? 

큰 의문은 의도를 깃발에게주는 방법입니까? XML로 의도 플래그를 설정하는 방법을 본 적이 없습니다. 나는 이미 자신의 환경 설정을 만들고 onClick() 중에 의도를 시작합니다. 하지만 계좌 환경 설정이 & 동기화 설정 컨텍스트에서 시작되고 클래스 로더가 내 수업을 찾을 수없는 것으로 보입니다.

  1. 는 의도로 플래그를 설정합니다

    나는 여기에 두 가지 솔루션을 참조하십시오.
  2. 하위 클래스 환경 설정 및 onClick()을 처리하여 활동을 시작하십시오. 하지만 내 수업을 어떻게 게시 할 수 있습니까?
+0

'AndroidRuntimeException'의 경우 다음을 확인하십시오. http://stackoverflow.com/questions/14328253/launch-intent-from-account-authenticator-accountpreferences-screen –

6

마침내 내 맞춤 환경 설정 활동을 성공적으로 시작했습니다. 피트 가을은 다음과 같은 XML 레이아웃을 유지 (위와 같이)해야한다는였다

<PreferenceScreen 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
<PreferenceCategory 
    android:title="Account settings" /> 
<PreferenceScreen 
    android:key="key" 
    android:title="General settings" 
    android:summary="Some summary"> 

    <!-- package relative class name--> 
    <intent 
     android:action="my.account.preference.MAIN"   
     android:targetClass="prefs.AccountPreferencesActivity.class"> 
    </intent>   
</PreferenceScreen> 
</PreferenceScreen> 

를 그리고 따라 AndroidManifest.xml에 항목 : 당신이 Android code를 보면

<activity 
    android:label="Account preferences" 
    android:name=".prefs.AccountPreferencesActivity"> 
    <intent-filter> 
     <action 
     android:name="my.account.preference.MAIN" /> 
     <category 
     android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
</activity> 

것은 당신이 찾을 수있는 다음 코드 줄을 사용하십시오.

private void updatePreferenceIntents(PreferenceScreen prefs) { 
    for (int i = 0; i < prefs.getPreferenceCount(); i++) { 
     Intent intent = prefs.getPreference(i).getIntent(); 
     if (intent != null) { 
      intent.putExtra(ACCOUNT_KEY, mAccount); 
      // This is somewhat of a hack. Since the preference screen we're accessing comes 
      // from another package, we need to modify the intent to launch it with 
      // FLAG_ACTIVITY_NEW_TASK. 
      // TODO: Do something smarter if we ever have PreferenceScreens of our own. 
      intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); 
     } 
    } 
} 

이러한 플래그는 XML에 지정된 의도에 플래그를 추가합니다. 그러나 이것은 PreferenceScreen의 모든 1 학년 아동에게만 적용됩니다. 내 잘못은 내가 PreferenceCategory에 내 Intent를 캡슐화했기 때문에 플래그가 OR 처리되지 않았기 때문입니다.

희망이 있습니다.

+0

안드로이드 매니페스트에 여러 동작 및 카테고리를 넣을 수 있습니다. 동일한 액티비티 태그에 대해, 그리고이 계정 환경 설정 액티비티가 안드로이드의 설정 계정 화면에서 시작될 것이고 어쩌면 툴바의 애플리케이션 설정과 어딘가에서 여러 액션을 정의 할 수 있기 때문입니다. 요점은이 계정 환경 설정 구현이 두 번 이상 사용된다는 것입니다. – Pomagranite