How to use LoaderManager in Android. Sample.

Published by Igor Khrupin on

Here is very simple example how to use LoaderManager from “android.support.v4.app” package.

This sample will help you create nice application which can very nice communicate with your web server.

The sample application looks like activity with ViewPager. Each Fragment in ViewPager adapter have implemented LoaderManager.LoaderCallbacks. Where “T” is returning type.
It can be String or complex List, Map, ets. with objects.

2014-10-23 13.53.45

You can run the Loader and when data is loaded then show it.
Below you can see how I use onLoadFinished method from LoaderManager.LoaderCallbacks interface for it.

@Override
	public Loader<String> onCreateLoader(int arg0, Bundle arg1) {
		return new MyLoader(getActivity(), url);
	}

	@Override
	public void onLoadFinished(Loader<String> arg0, String arg1) {
		textView.setText(arg1);
		hideProgress();
	}
Download it from github

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.