35

나는 안드로이드 3.0에서 을 사용하는 방법을 알아 내려고 노력하고 있지만 작동하지는 않습니다. 문서는 CursorLoader만을 사용하여 설명하지만 AsyncTaskLoader을 사용하고 있습니다.안드로이드의 로더 벌집

문서에서는 AsyncTaskLoader.loadInBackground() 만 구현하면되지만 getLoaderManager().initLoader() 이후에는 호출되지 않고 콜백에 로더가 만들어집니다.

Created new loader LoaderInfo{4040a828 #0 : ArticleDataLoader{4036b350}}을 말하는 디버그 메시지가 표시되어 성공적으로 생성 된 것으로 보입니다.

로더가 SDK에서 현재 손상되었거나 로더를 만든 후 호출해야하는 방법이 있습니까? (그들은 CursorLoader 예제에서 그렇게하지 않았다).

편집 :) ( 당신이 onLoadInBackground 경우 유효성을 검사 할나요 적어도 로딩을 시작 initLoader()에서 반환 로더에 forceLoad()를 호출하는 것 같다하지만이 제대로 회전을 처리 할 수 ​​없습니다 :(

+0

답변을 찾으면 알려 주시기 바랍니다. 나는 아무것도 찾을 수 없었다. –

+2

http://code.google.com/p/android/issues/detail?id=14944에도 '수정'메모와 동일한 해결 방법이 나와 있습니다. –

+0

예, 이것에 관한 버그 보고서입니다. – alexanderblom

답변

13

Dianne Hackborn이 버그 트래커에 답장하여 정적 라이브러리 구현을 참조했습니다. CursorLoader가 forceLoad()를 수행하고있는 이유는 이것이 작동하고있는 이유입니다.

은 버그 추적기에서 가장 간단한 경우에 당신을 위해 이것을 처리하는 클래스 내 부착 된 클래스를 참조하십시오 : 당신은 onStartLoading() 메소드를 오버라이드 (override) 할 필요가 http://code.google.com/p/android/issues/detail?id=14944

+4

그들은 실제로 CPL을 문서화 할 필요가 있습니다. < – schwiz

+1

그것은 정말 짜증납니다. 그래서 여기에 나와있는 예제는 : http://developer.android.com/reference/android/content/AsyncTaskLoader.html 지원 라이브러리를 사용한다면'onStartLoading'을 오버라이드하지 않으면 작동하지 않을 것입니다. – Blundell

+0

그래서 지금 제 자신의 참조 소스를 가지고 있습니다. 지원 라이브러리를 사용하는 ASyncTaskLoader : http://blog.blundell-apps.com/tut-asynctask-loader-using-support-library/ – Blundell

0

알렉스을 의미한다

onLoadInBackground() : 실제로드를 수행하기 위해 작업 스레드에서 호출 구현시 직접 결과를 전달해서는 안되지만이 메소드에서 결과를 반환해야하며 결과적으로 deliverResult (D)를 호출하게됩니다. 구현이 UI 스레드에서 결과를 처리해야하는 경우 deliverRes를 재정의 할 수 있습니다. ult (D)하고 그렇게해라.

+1

아니요, forceLoad()를 수행하지 않으면 호출되지 않습니다. – alexanderblom

1

. developer website의 예를보세요.

/** 
    * Handles a request to start the Loader. 
    */ 
    @Override protected void onStartLoading() { 
     if (mApps != null) { 
      // If we currently have a result available, deliver it 
      // immediately. 
      deliverResult(mApps); 
     } 

     // Start watching for changes in the app data. 
     if (mPackageObserver == null) { 
      mPackageObserver = new PackageIntentReceiver(this); 
     } 

     // Has something interesting in the configuration changed since we 
     // last built the app list? 
     boolean configChange = mLastConfig.applyNewConfig(getContext().getResources()); 

     if (takeContentChanged() || mApps == null || configChange) { 
      // If the data has changed since the last time it was loaded 
      // or is not currently available, start a load. 
      forceLoad(); 
     } 
    }