One of the biggest disadvantages of the Android system is power. Here we will optimize the download to save power as much as possible.
1. Transfer Data together as much as possible. Unlimited read of cache data will also increase power consumption. Generally, retrieving data every 2 to 5 minutes is the best option. You can avoid downloading duplicate data.
2. Use Google Cloud Messaging for Android (GCM) to push App update notifications. In this way, you do not need to create a separate network connection for updates.
Update policy
Set a proper frequency. It is best to allow users to modify the polling frequency.
Private void enableHttpResponseCache (){
Try {
Long httpCacheSize = 10*1024*1024; // 10 MiB
File httpCacheDir = new File (getCacheDir (), "http ");
Class. forName ("android.net. http. HttpResponseCache ")
. GetMethod ("install", File. class, long. class)
. Invoke (null, httpCacheDir, httpCacheSize );
} Catch (Exception httpResponseCacheNotAvailable ){
Log. d (TAG, "HTTP response cache is unavailable .");
}
}
Modify Network Connection Mode
In most cases, Wi-Fi consumes less power than 3G.
NetworkInfo activeNetwork = cm. getActiveNetworkInfo ();
Int PrefetchCacheSize = DEFAULT_PREFETCH_CACHE;
Switch (activeNetwork. getType ()){
Case ConnectivityManager. TYPE_WIFI:
......
Case ConnectivityManager. TYPE_MOBILE:
......
Default: break;
}