Search code examples
androidloaderasynctaskloader

Using Update Throttle in AsyncTaskLoader in Android


I am planning to use AsyncTaskLoader for my upcoming project. I have learned about Loader Callbacks, Loader Manager and AsyncTaskLoader.

I have also learned how to implement the asynctaskloader to perform network operation. But, I also want to show latest live feeds from server in my UI just like facebook does.

I have come across setUpdateThrottle() in asynctaskloader. I want to use setUpdateThrottle in my project, but I dont know how to use it. I have not come across any satisfactory resources in the web that could tell me how to use it, even official Android Blog does not clarify how to use setUpdateThrottle in asynctaskloader.

So, if anyone has successfully used setUpdateThrottle in asynctaskloader.


Solution

  • did you see this example !!!!!!?

    http://blog.gunawan.me/2011/10/android-asynctaskloader-exception.html

    see this part in above link

    private final LoaderCallbacks< AsyncResult < List < String >>> loaderCallbacks = new LoaderCallbacks< AsyncResult< List < String >>>() {
    
            @Override
            public Loader< AsyncResult < List < String>>> onCreateLoader(int id, Bundle args) {
                MyAsyncTaskLoader loader = new MyAsyncTaskLoader(TestActivity.this);
                loader.setUpdateThrottle(1000);
    
                return loader;
            }
    
            @Override
            public void onLoadFinished(Loader < AsyncResult < List < String >>> loader, final AsyncResult< List < String >> result) {
    
                Exception exception = result.getException();
                if (exception != null) {
                    Toast.makeText(TestActivity.this, exception.getMessage(), Toast.LENGTH_SHORT).show();
                } else {
                    // process the result
                }
            }
    
            @Override
            public void onLoaderReset(Loader < AsyncResult < List < String >>> loader) {
                loader.reset();
            }
        };