Skip to content

Commit 278296b

Browse files
retomeierAndroid Git Automerger
authored andcommitted
am 20f394d: Docs: Added efficient downloads Android U class
* commit '20f394df4db02c492d7920f4f366b777451c2067': Docs: Added efficient downloads Android U class
2 parents 1c4c320 + 20f394d commit 278296b

File tree

9 files changed

+510
-0
lines changed

9 files changed

+510
-0
lines changed
26.6 KB
Loading
16.2 KB
Loading
33.5 KB
Loading

docs/html/resources/resources_toc.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,30 @@
9797
</li>
9898
</ul>
9999
</li>
100+
101+
<li class="toggle-list">
102+
<div><a href="<?cs var:toroot ?>training/efficient-downloads/index.html">
103+
<span class="en">Transferring Data Without Draining the Battery</span>
104+
</a> <span class="new">new!</span></div>
105+
<ul>
106+
<li><a href="<?cs var:toroot ?>training/efficient-downloads/efficient-network-access.html">
107+
<span class="en">Optimizing Downloads for Efficient Network Access</span>
108+
</a>
109+
</li>
110+
<li><a href="<?cs var:toroot ?>training/efficient-downloads/regular_updates.html">
111+
<span class="en">Minimizing the Effect of Regular Updates</span>
112+
</a>
113+
</li>
114+
<li><a href="<?cs var:toroot ?>training/efficient-downloads/redundant_redundant.html">
115+
<span class="en">Redundant Downloads are Redundant</span>
116+
</a>
117+
</li>
118+
<li><a href="<?cs var:toroot ?>training/efficient-downloads/connectivity_patterns.html">
119+
<span class="en">Modifying Patterns Based on the Connectivity Type</span>
120+
</a>
121+
</li>
122+
</ul>
123+
</li>
100124

101125
<li class="toggle-list">
102126
<div><a href="<?cs var:toroot ?>training/search/index.html">
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
page.title=Modifying your Download Patterns Based on the Connectivity Type
2+
parent.title=Transferring Data Without Draining the Battery
3+
parent.link=index.html
4+
5+
trainingnavtop=true
6+
previous.title=Redundant Downloads are Redundant
7+
previous.link=redundant_redundant.html
8+
9+
@jd:body
10+
11+
<div id="tb-wrapper">
12+
<div id="tb">
13+
14+
<h2>This lesson teaches you to</h2>
15+
<ol>
16+
<li><a href="#WiFi">Use Wi-Fi</a></li>
17+
<li><a href="#Bandwidth">Use greater bandwidth to download more data less often</a></li>
18+
</ol>
19+
20+
<h2>You should also read</h2>
21+
<ul>
22+
<li><a href="{@docRoot}training/monitoring-device-state/index.html">Optimizing Battery Life</a></li>
23+
</ul>
24+
25+
</div>
26+
</div>
27+
28+
<p>When it comes to impact on battery life, not all connection types are created equal. Not only does the Wi-Fi radio use significantly less battery than its wireless radio counterparts, but the radios used in different wireless radio technologies have different battery implications.</p>
29+
30+
<h2 id="WiFi">Use Wi-Fi</h2>
31+
32+
<p>In most cases a Wi-Fi radio will offer greater bandwidth at a significantly lower battery cost. As a result, you should endeavor to perform data transfers when connected over Wi-Fi whenever possible.</p>
33+
34+
<p>You can use a broadcast receiver to listen for connectivity changes that indicate when a Wi-Fi connection has been established to execute significant downloads, preempt scheduled updates, and potentially even temporarily increase the frequency of regular updates as described in <a href="{@docRoot}training/monitoring-device-state/index.html">Optimizing Battery Life</a> lesson <a href="{@docRoot}training/monitoring-device-state/connectivity-monitoring.html">Determining and Monitoring the Connectivity Status</a>.</p>
35+
36+
<h2 id="Bandwidth">Use Greater Bandwidth to Download More Data Less Often</h2>
37+
38+
<p>When connected over a wireless radio, higher bandwidth generally comes at the price of higher battery cost. Meaning that LTE typically consumes more energy than 3G, which is in turn more expensive than 2G.</p>
39+
40+
<p>This means that while the underlying radio state machine varies based on the radio technology, generally speaking the relative battery impact of the state change tail-time is greater for higher bandwidth radios.</p>
41+
42+
<p>At the same time, the higher bandwidth means you can prefetch more aggressively, downloading more data over the same time. Perhaps less intuitively, because the tail-time battery cost is relatively higher, it's also more efficient to keep the radio active for longer periods during each transfer session to reduce the frequency of updates.</p>
43+
44+
<p>For example, if an LTE radio is has double the bandwidth and double the energy cost of 3G, you should download 4 times as much data during each session&mdash;or potentially as much as 10mb. When downloading this much data, it's important to consider the effect of your prefetching on the available local storage and flush your prefetch cache regularly.</p>
45+
46+
<p>You can use the connectivity manager to determine the active wireless radio, and modify your prefetching routines accordingly:</p>
47+
48+
<pre>ConnectivityManager cm =
49+
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
50+
51+
TelephonyManager tm =
52+
(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
53+
54+
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
55+
56+
int PrefetchCacheSize = DEFAULT_PREFETCH_CACHE;
57+
58+
switch (activeNetwork.getType()) {
59+
case (ConnectivityManager.TYPE_WIFI):
60+
PrefetchCacheSize = MAX_PREFETCH_CACHE; break;
61+
case (ConnectivityManager.TYPE_MOBILE): {
62+
switch (tm.getNetworkType()) {
63+
case (TelephonyManager.NETWORK_TYPE_LTE |
64+
TelephonyManager.NETWORK_TYPE_HSPAP):
65+
PrefetchCacheSize *= 4;
66+
break;
67+
case (TelephonyManager.NETWORK_TYPE_EDGE |
68+
TelephonyManager.NETWORK_TYPE_GPRS):
69+
PrefetchCacheSize /= 2;
70+
break;
71+
default: break;
72+
}
73+
break;
74+
}
75+
default: break;
76+
}</pre>

0 commit comments

Comments
 (0)