Android app optimized for extended battery life

Source: Internet
Author: User
Tags xml attribute

Disable broadcast Receivers

Make sure that the broadcast receiver runs instructions when it really needs to, broadcast the receiver in Onresume, and disable it in OnPause.

When a broadcast receiver is declared in a manifest file, it is configured to be disabled in advance by default

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


Internet

1. Background data. When data is transferred in the background. Infers the return value of the Connectivitymanager getbackgrounddatasetting (), assuming true. Data is transferred in the background, assuming false, the data is not transferred in the background

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 data transmission 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. Picture file using JPEG instead of PNG

3. Use resources that match the resolution of the device (for example. Don't have to download 1920x1080 pictures for 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. Use the appropriate location service. Android offers three location services, GPS, network positioning, and passive positioning (your app waits for other apps.) The service or system component makes a location request and then receives 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

expressed using Elapsed_time and RTC. Assume that the device does not wake up and then wait for the device to wake up to run the corresponding action

So try to use both of these parameters

In addition, the use of Alarmmanager setinexactrepeating is also able to achieve the purpose of power saving, the main difference is how the system to arrange reminders, Android can adjust the actual trigger events. Triggering multiple reminders at the same time (possibly from multiple apps) makes the reminder more energy-efficient and avoids unwanted wake-up.


WakeLock

When you get Wakelock, be sure to release

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

It is assumed that the screen used is associated with the view in the activity, and that the XML attribute Android:keepscreenon can be used in the layout file.

The advantage of this approach is that you do not have to risk forgetting to release the Wakelock and leave it to the system for processing. You do not need to set permissions in the manifest file.

Android app optimized for extended battery life

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.