RoboSpice is an Android Library that makes it easier to write asynchronous network requests. It is production-ready, open sourced and includes a large range of features.
@Override
public
void
onLoadFinished(Loader>
personLoader,
List
result)
{
listPerson.clear();
listPerson.addAll(result);
personListAdapter.notifyDataSetChanged();
}
@Override
public
void
onLoaderReset(Loader>
loader)
{
listPerson.clear();
personListAdapter.notifyDataSetChanged();
}
//..
loader
follows,
as
an
inner
class
public
PersonLoader(Context
context)
{
super(context);
}
@Override
public
List
loadInBackground()
{
return
dataSourceOrDomainModel.getListPerson(
progressHandler
);
}
}
Loaders have been designed for cursors, they don't fit when it comes to networking : Asynchronous code is too tied to Activity life cycle. • Request's result is lost when you leave the Activity. • If you leave the Activity, request dies : users MUST wait for result • (they can go to other apps but not to other activities within the app). • Exception management is left to the dev without any support. • And code is a bit bloated by generics...