1 / 23

Android Memory management techniques | Best Practice

<br>To have a great app you should make your app more memory efficient which help you to make you app work smoothly with less memory usage while running the app on the Android phone.This PDF Includes Android Memory Management and explains various aspects that play a role in the management system. Improving memory management, detecting and avoiding memory leaks, and analyzing memory usage are covered.

Singsys
Télécharger la présentation

Android Memory management techniques | Best Practice

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Two types of memories in Android Clean RAM Android makes memory available to the system through paging and memory-mapping techniques. files and resources are kept in mapped pages which can be easily recovered from disk hence these can be paged out and memory can be released for the system. Dirty RAM Dirty RAM is the memory that cannot be paged out as well proves to be expensive if running in the background. Maximum memory inside a running application is dirty memory and this is the one that can be used for memory optimization.

  2. Android Memory Overview All applications are recognized by android as running process or cached process. Android kills one or multiple cached processes when there is requirement of memory for running process. The process killed under cached process are in LRU (least recently used) order. Memory Optimization: Best practices for enhanced memory usage Keeping your system from running out of memory helps in boosting the overall memory usage and performance of Android thereby ensuring delightful user experience.

  3. JOB Scheduler API Code Snippet

  4. Android Doze • When smartphone is kept idle for hours usually during night with screen off and the device is stationary, this might drain some battery. • Now android doze is triggered and it will defer the background tasks, syncs, alarms and Wi-Fi scan until a maintenance window is scheduled. • Doze will batch all background activities inside a single batch to extend battery life by good margin.

  5. Android Doze

  6. Android Doze Extended • When device is in pocket (not stationary) with screen off. • the lighter doze version will be active and restrict lesser number of background tasks. • During this time there will be regular maintenance windows.

  7. Android Doze Extended

  8. Doze Modes Comparison Extended doze mode produce maintenance window at short interval to ensure apps are ready when user wants to use the device again.

  9. Doze Optimization • High Priority GSM messages are the best method to deliver the time critical messages to the app. It enables app to access the network to ensure important notifications reach the user • Foreground services will continue to work despite the ongoing battery optimization.

  10. Doze Optimization Whether the smartphone is stationary or not, when the screen is off for a while means user isn’t engaged with the device and that is an opportunity to conserve the battery power.

  11. App Standby App Standby is designed to limit the background syncs and tasks for apps that user isn’t interested at the moment.

  12. App Standby

  13. Monitoring the Battery Level and Charging State It is good practise to notice battery level and charging state before performing application update. If the device is charging over AC(wall charger) refresh rate can be maximised without affecting battery life. In case device is unplugged limiting the update rate will help in maximising battery life.

  14. Monitoring the Battery Level and Charging State

  15. Code Snippet to determine Charging State and Method // Are we charging / charged? int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; // How are we charging? int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB; boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;

  16. Monitor Connectivity State to Limit Battery Drain • Background services schedule updates to an application. They do it on behalf of internet resources and cache data. • This schedule can negatively impact battery life takes place especially during no internet state or weak internet connection. • You can handle this tricky situation smartly by knowing the device connectivity status with connectivity manager

  17. Monitor Connectivity State to Limit Battery Drain Connectivity manager will also help in decoding the connection category and accordingly you can decide either to continue with an update to the application or restrict it now. Connectivity manager code snippet to query the active network and subsequent internet connectivity. ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

  18. Key Steps required to Minimize Server Updates and Optimize the Battery Drain An Android application needs to activate the wireless radio and create the connection to check the available updates on the server. This will cause unnecessary battery drain. Once we understand the device state, network connectivity and user behavior then accordingly periodic update can be scheduled.

  19. Key Steps to Minimize Server Updates and Optimize the Battery Drain

  20. Key Steps required to Minimize Server Updates and Optimize the Battery Drain Google Cloud Messaging: A mobile notification service via which server will notify the application when data is available for download. All apps which require periodic updates from a remote server can utilise this service which ensure update notifications to the app are carried out using single GCM connection. This approach will reduce unnecessary connections to check for periodic updates as a new connection is created only when an update is available

  21. Key Steps to Minimize Server Updates and Optimize the Battery Drain Set the frequency to minimum: Another way to optimize is to set the update frequency as low as possible at the same time ensuring zero negative impact on user experience. This will make the best balance between battery usage and data updates. Inexact Repeating Alarms: If multiple alarms are set to go off around the same time then android can phase shift the alarm fire time for various application in a manner that all these apps will receive the alarm at the same time. This will allow all applications to perform network updates with a single

  22. Key Steps to Minimize Server Updates and Optimize the Battery Drain activation of wireless radio. Exponential back-off methods: In this method updates are scheduled after close monitoring the app usage and reduce update frequency dynamically, generally frequency is reduced for the apps which have not been used after the last update. HTTP Cache and HTTP Response Cache: This technique is used to avoid downloading duplicate files by keeping them in case. Such files once stored inside case directory thereby, eliminating the need to download it every time

More Related