Android app optimized for extended battery life

Source: Internet
Author: User
Tags xml attribute

Disable broadcast Receivers

Ensure that the broadcast receiver executes the instruction when it is really needed, in which broadcast the receiver in Onresume, disabled in OnPause,

When a broadcast sink is declared in a manifest file, it is previously configured as disabled by default

<receiver android:name= ". Batterreceiver "android:enabled=" false ">


Internet

1. Background data, when transmitting data in the background, determine the return value of Connectivitymanager getbackgrounddatasetting (), if true, background data transfer, if False, no background data transfer

2. Data transmission, mobile phone equipment, the most power consumption of the components in order: wi-fi-"3g-" cpu-"screen (all at the highest load of data), so in the transmission of data must not take a long time to occupy the network resources, but should be a sudden transmission of all the resources required for a period of time, There is a paper on this: http://www.research.att.com/articles/featured_stories/2011_03/201102_Energy_efficient?fbid= 1n507ukp1ch, the final conclusion is: the single mostimportant measure:transmit as much data as possible in a single burst and then End the connection.

1. Use gzip to compress text data and use the Gzipinputstream class to access data

2. If possible, use JPEG instead of PNG image file

3. Use a resource that matches the resolution of the device (for example, you do not have to download 1920x1080 images for a 96x54 size display space)


Position

1. Log off the location listener when no listening position is required

2. Reduce the frequency of update locations

3. With the right location service, Android offers three location services, GPS, network positioning, passive positioning (your app waits for other apps, services or system components to make location requests, and then updates with other listeners)

4. Use the criteria category to filter the appropriate location services

5. Use the last known location to improve the user experience


Sensor

Reduce the frequency of sensor data update to achieve the purpose of power saving


Graphics

In the eighth chapter of the book on performance optimization for Android applications, there is a special introduction


Remind Alarmmanager

Elapsed_time

Elapsed_time_wakeup

Rtc

Rtc_wakeup

Use Elapsed_time and RTC to indicate that when the device is not woken up when it is finished, it waits for the device to be awakened before performing the corresponding action

So try to use these two parameters

In addition, the use of Alarmmanager setinexactrepeating can also achieve power saving purposes, the main difference is that when the system to arrange reminders, Android can adjust the actual trigger events, while triggering multiple reminders (possibly from multiple applications), this reminder more energy-saving , the system also avoids unnecessary wake-up.


WakeLock

When you get Wakelock, be sure to release

To prevent problems, it is recommended to use the Wakelock.acquire () version with a timeout, and he will release Wakelock after the time limit is exceeded.

If the screen used is associated with the view in activity, you can also use the XML attribute Android:keepscreenon in the layout file. The advantage of this approach is that you do not have to risk forgetting to release wakelock, to be processed by the system, or to set permissions in the manifest file

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.