So far, the blog list example has assumed a single layout for all devices and orientations. Of course, we know that some phones are much larger than others, and tablets are larger than phones, and landscape vs portait orientations provide for very different amounts of screen real estate to work with. Having a single layout accounts for none of this, and inevitably forces the design to the lowest common denominator (a small phone in portrait orientation).
Providing different layouts means having reusable UI components becomes very important. In Android, these are called fragments. The Blog List app follows the typical example for which fragments are useful: a list of items that provide additional detail about a selected item.
Today I’ll be modifying the Blog List example to add a blog view activity, and utilizing Dagger for dependency injection and Butterknife for view injection.
Also, if you’ve been following along with my Blog List series, you’ll noticed the code has gone through a bit of refactoring in this iteration. Specifically, I’ve gotten rid of the VolleyBlogPostRequest and BlogPostListener in favor of anonymous inner classes. This allowed me to keep the list of blog posts available for the ListView’s onItemClickedListener.
So, being introduced today:
- Navigating from one activity to another
In my previous iterations of the of the Blog List example, the BlogListService just returned a hardcoded list of BlogPost objects. In this post, we will actually retrieve the list of BlogPost objects from a restful JSON service.
Ideally, you can eliminate much of the HTTP traffic by using some sort of a client side caching layer. This is where Volley comes in.
So, in this post I’ll show two things:
- One of the many ways to consume JSON and convert it into java objects
- The use of Volley as an asynchronous network thread management and caching solution (replacing the AsyncTaskLoader in the prior examples).