The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
The first step towards addressing bandwidth concerns is to get a better picture of how much bandwidth you are actually consuming, when, and under what conditions. Only then will you be able to determine where your efforts need to be applied and whether those efforts are actually giving you positive results. This chapter will examine a handful of ways you can determine how much bandwidth you are really using in your application.
Understanding this chapter requires that you have read the core chapters and understand how Android apps are set up and operate.
Many times, you are best served by measuring your bandwidth consumption right on the device itself:
Hence, in addition to perhaps other off-device techniques, you really should consider one of the on-device approaches outlined in the following sections.
The preceding chapter outlined how to use the
TrafficStats class to collect metrics on the bandwidth consumed by
applications (including yours) and for the device as a whole. This
gives you the most flexibility, because you can write your own code
to collect whatever portion of this data you need. It can address all
of the bullets shown above, for example.
It is not perfect, though:
For more casual use, the Settings app in most Android devices offers a “Data Usage” screen that shows how much bandwidth has been consumed over a period of time:
Figure 1001: Settings, App, Data Usage Screen, Data Usage Graph
Scrolling further down will give you details of what apps were involved in that data usage:
Figure 1002: Settings, App, Data Usage Screen, Data Usage “Blame List”
Tapping on any one of those list items will give you a bit more detail, specifically how much of that bandwidth was consumed while the app was in the foreground or the background:
Figure 1003: Settings, App, Data Usage Screen, Data Usage App Details
The preview of this section will not appear here for a while, due to a time machine mishap.
The preview of this section took that left turn at Albuquerque.