Fetching JSON from Flickr
Finally, modify the AsyncTask in PhotoGalleryFragment to call the new fetchItems() method.
Listing 25.9 Calling fetchItems() (PhotoGalleryFragment.java)
public class PhotoGalleryFragment extends Fragment {
...
private class FetchItemsTask extends AsyncTask<Void,Void,Void> {
@Override
protected Void doInBackground(Void... params) {
try {
String result = new FlickrFetchr()
.getUrlString("https://www.bignerdranch.com");
Log.i(TAG, "Fetched contents of URL: " + result);
} catch (IOException ioe) {
Log.e(TAG, "Failed to fetch URL: ", ioe);
}
new FlickrFetchr().fetchItems();
return null;
}
}
}
Run PhotoGallery and you should see rich, fertile Flickr JSON in Logcat, like Figure 25.9. (It will help
to search for “FlickrFetchr” in the Logcat search box.)
Figure 25.9 Flickr JSON in Logcat
Unfortunately the Android Studio Logcat window does not wrap the output nicely as of this writing.
Scroll to the right to see more of the extremely long JSON response string. (Logcat can be finicky. Do
not panic if you do not get results like ours. Sometimes the connection to the emulator is not quite right
and the log messages do not get printed out. Usually it clears up over time, but sometimes you have to
rerun your application or even restart your emulator.)