Skip to content

Instantly share code, notes, and snippets.

@indywidualny
Created May 22, 2015 05:00
Show Gist options
  • Save indywidualny/117fc3f454dfbbda15c5 to your computer and use it in GitHub Desktop.
Save indywidualny/117fc3f454dfbbda15c5 to your computer and use it in GitHub Desktop.
saxrssreader working example, AsyncTask
05-22 07:00:13.546 19452-19452/? I/art﹕ Late-enabling -Xcheck:jni
05-22 07:00:13.775 19452-19499/org.indywidualni.test D/OpenGLRenderer﹕ Use EGL_SWAP_BEHAVIOR_PRESERVED: true
05-22 07:00:13.790 19452-19452/org.indywidualni.test D/Atlas﹕ Validating map...
05-22 07:00:13.834 19452-19499/org.indywidualni.test I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 01/15/15, ab0075f, Id3510ff6dc
05-22 07:00:13.835 19452-19499/org.indywidualni.test I/OpenGLRenderer﹕ Initialized EGL, version 1.4
05-22 07:00:13.862 19452-19499/org.indywidualni.test D/OpenGLRenderer﹕ Enabling debug mode 0
05-22 07:00:14.068 19452-19498/org.indywidualni.test I/RSS Reader﹕ ********** doInBackground: Feed loaded properly. OK! **********
05-22 07:00:14.069 19452-19452/org.indywidualni.test I/onPostExecute﹕ Tue Mar 03 13:15:04 CET 2015 # Introduction to Java: input, output, file operations # http://feedproxy.google.com/~r/KorasDevBlog/~3/nNt5ixDO0zQ/introduction-to-java-input-output-file-operations
05-22 07:00:14.069 19452-19452/org.indywidualni.test I/onPostExecute﹕ Tue Feb 24 09:40:25 CET 2015 # Shared Preferences, Preference Fragment & transparent Navbar # http://feedproxy.google.com/~r/KorasDevBlog/~3/neb5C-m-VlY/shared-preferences-and-preferencefragment
05-22 07:00:14.069 19452-19452/org.indywidualni.test I/onPostExecute﹕ Tue Feb 17 01:53:06 CET 2015 # An advanced WebView with some cool features # http://feedproxy.google.com/~r/KorasDevBlog/~3/7ZRmpNRgaAU/an-advanced-webview-with-some-cool-features
05-22 07:00:14.069 19452-19452/org.indywidualni.test I/onPostExecute﹕ Sun Feb 08 20:01:46 CET 2015 # Introduction: Installing Java (JDK) and Android Studio on Arch Linux # http://feedproxy.google.com/~r/KorasDevBlog/~3/fqwX_ES4BOo/introduction
package org.indywidualni.test;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import java.net.URL;
import java.util.ArrayList;
import nl.matshofman.saxrssreader.RssFeed;
import nl.matshofman.saxrssreader.RssItem;
import nl.matshofman.saxrssreader.RssReader;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// TODO: Get feed url (String) from shared prefs
String url = "http://feeds.feedburner.com/KorasDevBlog";
// start AsyncTask
new rssReaderTask().execute(url);
}
private class rssReaderTask extends AsyncTask<String, Void, ArrayList<RssItem>> {
@Override
protected ArrayList<RssItem> doInBackground(String... params) {
try {
URL url = new URL(params[0]);
RssFeed feed = RssReader.read(url);
Log.i("RSS Reader", "********** doInBackground: Feed loaded properly. OK! **********");
return feed.getRssItems();
} catch (Exception ex) {
Log.i("RSS Reader", "********** doInBackground: Feed error! **********");
return null;
}
}
@Override
protected void onPostExecute(ArrayList<RssItem> result) {
try {
for (RssItem rssItem : result)
Log.i("onPostExecute", rssItem.getPubDate() + " # " + rssItem.getTitle() + " # " + rssItem.getLink());
} catch (NullPointerException ex) {
Log.i("onPostExecute", "********** Holy crap! **********");
}
// TODO: Do more with result here, invoke all the methods
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment