RSS Parser 2.0: bye bye Async Task, welcome Coroutines

Marco Gomiero
Dec 22, 2018 · 3 min read
import com.prof.rssparser.Article
import com.prof.rssparser.Parser
//url of RSS feed
private val url = "https://www.androidauthority.com/feed"
coroutineScope.launch(Dispatchers.Main) {
try {
val parser = Parser()
val articleList = parser.getArticles(url)
// The list contains all article's data. For example you can use it for your adapter.
} catch (e: Exception) {
// Handle the exception
}
}
import com.prof.rssparser.Article;
import com.prof.rssparser.OnTaskCompleted;
import com.prof.rssparser.Parser;
Parser parser = new Parser();
parser.onFinish(new OnTaskCompleted() {
//what to do when the parsing is done
@Override
public void onTaskCompleted(List<Article> list) {
// The list contains all article's data. For example you can use it for your adapter.
}
//what to do in case of error
@Override
public void onError(Exception e) {
// Handle the exception
}
});
parser.execute(urlString);

Marco Gomiero

Written by

Computer Engineer | Android Developer | Software Engineer @Uniwhere | Community Manager @gdgvenezia

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade