In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "what is the Doze and App Standby mode of Android". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Optimizing for Doze and App Standby
Starting with Android6.0, Android provides two power-saving features to extend battery life: Doze and App Standby
Presentation: when the device is not connected to the power supply and the device enters Doze mode, the system will keep the application in the App Standby state by delaying the background CPU operation and network activity of the application that the user has not used recently, so as to reduce battery consumption. Google said that when tested on Nexus5 and Nexus6, the average battery life increased by 30% when the screen was turned off.
Version requirements: Android6.0 (API level 23) and later
Developer influence: in order to ensure the best user experience, it is necessary for developers to test the application in Doze and App Standby mode and adjust the code accordingly.
Understanding Doze1. When the device enters Doze sleep mode:
The user does not operate the device for a period of time
Screen off
The device is not connected to the power supply to charge.
What are the changes in the application in 2.Doze mode:
The system attempts to save batteries by restricting application access to the network and CPU-intensive services
Prevent applications from accessing the network, defer application work, synchronization, and standard alerts
The system periodically provides a short period of time for applications to complete delayed work activities, during which the system will provide maintainable window applications to access the network and run waiting synchronization, work, and alarm activities.
The five states of Doze mode are as follows:
ACTIVE: mobile device is active
INACTIVE: screen shuts down and becomes inactive
IDLE_PENDING: put App into waiting idle standby state every 30 minutes
IDLE: idle statu
IDLE_MAINTENANCE: handling pending tasks
As shown in the following figure, the Doze period provides a short interval (30s) for applications to use the network and handle pending activities.
From this picture, we can see that after the system enters Doze mode, the system will deal with the pending tasks at regular intervals, and as time goes by, the intervals will become longer and longer, so as to reduce power consumption.
3. Exit Doze mode (the system exits hibernation and all applications return to normal activity):
The user wakes up the device to move, open the screen
Or the device is connected to power.
What are the limitations of 4.Doze?
Internet connections will be prohibited.
Wake Lock will be blocked.
AlarmManager scheduled tasks are deferred to the next maintenance window, unless you use the method provided by AlarmManager: setAndAllowWhileIdle () or setExactAndAllowWhileIdle ()
The system will not scan hotspot WIFI
Synchronous work will be prohibited
Do not allow JobScheduler to schedule tasks
5. What is the way to adapt to the Doze mode?
Doze affects AlarmManager alarm clock and timer management activities. Two new methods are introduced in Android6.0: setAndAllowWhileIdle () and setExactAndAllowWhileIdle (). Calling two methods can make the system respond to scheduled tasks in Doze mode.
Doze mode restricts network connectivity, which will affect the App experience if the application relies on real-time information. Then you need to use Google Cloud Messaging (GCM) Google Cloud messaging (more on later).
6. Methods for testing Doze and App Standby modes (Adb command)
Test Doze mode
First make sure that your hardware or virtual device is an Android6.0 or later system
Connect the device to the development machine and install your app
Run app and have it run the activity
Turn off the screen of the device
Run the following adb command to put the system into Doze mode:
$adb shell dumpsys battery unplug
$adb shell dumpsys deviceidle step
Observe whether your app performance needs to be optimized and improved.
Test App Standby mode
Steps 1-3 are the same as testing Doze mode
Run the following adb command to force the system into App Standby mode:
$adb shell dumpsys battery unplug
$adb shell am set-inactive true
The simulation wakes up your application using the following command:
$adb shell am set-inactive false
$adb shell am get-inactive
Watch your App to ensure that the application returns to normal from standby mode, App notification and its back activity can achieve the desired results.
Understanding App Standby
When the user does not touch the application for a period of time, the application is in the App Standby state and the system marks the App as idle. The application exits the App Standby state unless any of the following conditions are triggered:
The user initiates the App
The App currently has a foreground process (or contains an active foreground service, or is used by another activity or foreground service)
App generates a Notification that the user can see on the lock screen or notification tray, and when the user equipment is plugged in, the system will release the standby state of the App, allowing them to freely connect to the network and perform unfinished work and synchronization. If the device is idle for a long time, the system will allow idle App to access the network once a day.
The difference between Doze and App Standby:
Doze mode requires screen closure (usually sleep at night or screen shutdown for a long time to enter), while App Standby does not require screen closure, and App access to the background for a period of time will be limited by connecting to the network and so on.
Using GCM to Interact with Your App While the Device is Idle1. What is GCM?
Google Cloud Messaging (GCM) is a cloud-to-device service that allows you to support real-time messaging between cloud services and applications on Android devices.
GCM provides a persistent link to the cloud that can be shared by all applications that require real-time messaging. This shared link significantly optimizes battery consumption so that it does not have to allow multiple applications to maintain their own separate persistent links and cause the battery to drain quickly.
For this reason, the official advice is: if your application requires messaging to integrate with back-end services, we strongly recommend using GCM as much as possible instead of maintaining your own web links separately.
GCM messages have a high priority, do not affect the Doze schema, and do not affect the state of other applications. This means that your applications can use them to communicate while minimizing the impact of batteries on the entire system and device.
The following is the official explanation of GCM:
An GCM implementation includes Google connection servers, application servers and client applications that interact with each other in your environment through HTTP or XMPP protocol connection servers.
$adb shell dumpsys deviceidle whitelist +
$adb shell dumpsys deviceidle
This is the end of the content of "what is the Doze and App Standby mode of Android". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.