[Android traffic] adjust the frequency of timing updates (C2DM and Backoff algorithms)

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/kesenhoo/article/details/7395253

Minimizing the Effect of Regular updates[minimizing the side effects of a timed update operation]
    • The best timing update frequency is indeterminate and is usually determined by the device status, network connection status, user behavior, and user-defined preferences.
    • Optimizing Battery Life ("Android Training-04" optimizes battery Lifetime) This chapter discusses how to modify the update frequency based on the device status. It describes how to turn off background services when disconnecting from the network, and reduce the frequency of updates when the battery level is low.
    • This lesson will describe how frequently the update is made to minimize the impact of the update operation on the radio state machine.
    • The use of C2DM and exponential backoff algorithm
Use the Cloud to Device Messaging as a alternative to polling[using C2DM as one of the polling methods]For more information about Android Cloud to Device Messaging (C2DM), please refer to: http://code.google.com/intl/zh-CN/android/c2dm/
    • Each time the app goes to the server to check for updates, it activates the radio, which creates unnecessary energy consumption (in the case of 3G, it consumes almost 20 seconds of energy).
    • C2DM is a lightweight mechanism for transferring data from the server to a specific app. Using C2dm,server will notify the app when new data is available in an app [a bit like the type of push text message].
    • This event-driven mode notifies the app to create a network connection to get the data when only the data is updated (it obviously reduces the number of apps and, of course, a lot of power) than the polling method (the app needs to request data from the server in order to get the latest data in time), C2DM.
    • C2DM needs to operate by using fixed TCP/IP. When you can implement a fixed IP on your device, it's best to use C2DM. [This place should not be a fixed IP in the traditional sense, it can be understood as a conversation case]. Obviously, using C2DM reduces the number of network connections, optimizes bandwidth, and reduces power consumption.
Optimize Polling with inexact repeating Alarms and exponential backoffs[optimizes polling operations by unscheduled repetitive reminders and exponential backoff]
    • If you need to use a polling mechanism, without compromising the user experience, of course, set the default update frequency to be as low as possible [reduce battery waste].
    • An easy way is to give the user the option of updating frequency, allowing the user to deal with how to balance the timeliness of data and the consumption of power.
      • When the settings are scheduled for update operations, you can use an indeterminate reminder to allow the system to move the current operation (such as a delay).
int alarmtype = alarmmanager.elapsed_realtime;   long interval = alarmmanager.interval_hour;   long start = System.currenttimemillis () + interval;  Alarmmanager.setinexactrepeating (Alarmtype, start, interval, pi);  
      • If multiple reminders have been "directed", then there is a good chance that a point will be triggered at the same time, so that multiple operations can be done in the same radio state.
      • If possible, set the type of reminder to Elapsed_realtime or RTC instead of _wakeup. This can further reduce the amount of power consumed while waiting to be triggered at the same time.
      • We can also reduce the frequency of updates selectively by the frequency at which the app is used.
    • Another method uses the exponential backoff algorithm (exponential back-off algorithm) to reduce the update frequency in cases where the app has not been used since the last update operation. Of course, we can also use some similar exponential backoff methods.
Sharedpreferences SP =context.getsharedpreferences (PREFS, context.mode_world_readable); Booleanappused = Sp.getboolean (prefs_appused,false); LongUpdateInterval =Sp.getlong (Prefs_interval, default_refresh_interval); if(!appused)if((updateinterval *= 2) >max_refresh_interval) UpdateInterval=Max_refresh_interval; Editor SpeDIt=Sp.edit (); Spedit.putboolean (prefs_appused,false);  Spedit.putlong (Prefs_interval, updateinterval);    Spedit.apply ();  Rescheduleupdates (UpdateInterval);  Executeupdateorprefetch (); 
    • The cost of initializing a network connection does not change if the data has been successfully downloaded. We can use the exponential backoff algorithm to reduce the number of repeated attempts (retry) to avoid wasting power. For example:
Private void Retryin (long  interval) {     boolean success = Attempttransfer ();            if (! success) {      Retryin (interval< max_retry_interval?)                Interval* : Max_retry_interval);           }  }  

PostScript:This lesson refers to C2DM and exponential backoff algorithm, in fact, these details are worthy of our attention, if it can be applied in the actual project, it is clear that the quality will be relatively high. Thank you!learn from: http://developer.android.com/training/efficient-downloads/regular_updates.htmlReprint Please specify the Source:Http://blog.csdn.net/kesenhoo, thank you!

[Android Traffic] Adjust the frequency of timed updates (C2DM and Backoff algorithms)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.