当前位置: 首页 > news >正文

Application的onLowMemory从Android API 34开始系统不再触发,从API 35开始废弃

Application的onLowMemory从Android API 34开始系统不再触发,从API 35开始废弃

Android的Application的onLowMemory()是在ComponentCallbacks定义实现,源代码链接 https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/content/ComponentCallbacks.java :

package android.content;import android.annotation.NonNull;
import android.content.res.Configuration;/*** The set of callback APIs that are common to all application components* ({@link android.app.Activity}, {@link android.app.Service},* {@link ContentProvider}, and {@link android.app.Application}).** <p class="note"><strong>Note:</strong> You should also implement the {@link* ComponentCallbacks2} interface, which provides the {@link* ComponentCallbacks2#onTrimMemory} callback to help your app manage its memory usage more* effectively.</p>*/
public interface ComponentCallbacks {/*** Called by the system when the device configuration changes while your* component is running.  Note that, unlike activities, other components* are never restarted when a configuration changes: they must always deal* with the results of the change, such as by re-retrieving resources.** <p>At the time that this function has been called, your Resources* object will have been updated to return resource values matching the* new configuration.** <p>For more information, read <a href="{@docRoot}guide/topics/resources/runtime-changes.html"* >Handling Runtime Changes</a>.** @param newConfig The new device configuration.*/void onConfigurationChanged(@NonNull Configuration newConfig);/*** This is called when the overall system is running low on memory, and* actively running processes should trim their memory usage.  While* the exact point at which this will be called is not defined, generally* it will happen when all background process have been killed.* That is, before reaching the point of killing processes hosting* service and foreground UI that we would like to avoid killing.** @deprecated Since API level 14 this is superseded by*             {@link ComponentCallbacks2#onTrimMemory}.*             Since API level 34 this is never called.*             Apps targeting API level 34 and above may provide an empty implementation.*/@Deprecatedvoid onLowMemory();
}

关于onLowMemory(),Android系统源代码这么说:

  * @deprecated Since API level 14 this is superseded by
     *             {@link ComponentCallbacks2#onTrimMemory}.
     *             Since API level 34 this is never called.
     *             Apps targeting API level 34 and above may provide an empty 

从 API 34开始,该方法过时了,不再被触发回调。

Android官方链接说明:

https://developer.android.com/reference/android/content/ComponentCallbacks#onLowMemory()

从API 35开始,废弃。此后这里是一个空实现。

Android理解onTrimMemory中ComponentCallbacks2的内存警戒水位线值-CSDN博客文章浏览阅读751次,点赞8次,收藏8次。Android的ComponentCallbacks2接口定义了内存警戒水位线值,用于在系统内存不足时通知应用释放资源。从API 34开始,仅保留TRIM_MEMORY_BACKGROUND(40)和TRIM_MEMORY_UI_HIDDEN(20)两个有效值,分别表示进程进入后台LRU列表和UI不再可见时应释放资源。开发者不应直接比较值大小,而应判断是否大于等于某个级别。如Glide框架会根据不同级别释放不同量的内存资源。该机制能有效帮助系统管理内存,延长应用进程存活时间。 https://blog.csdn.net/zhangphil/article/details/149119633Android之Application的onTerminate能监听应用退出吗?-CSDN博客文章浏览阅读3w次,点赞8次,收藏9次。 Android之Application的onTerminate能监听应用退出吗?一些Android开发者在不经意间发现Android的Application中有一个公开的回调方法:onTerminate()继而想当然的认为该方法即是Android的整个App应用退出后的回调,因为Terminate的词面意思就是..._onterminate https://blog.csdn.net/zhangphil/article/details/81232302

http://www.xdnf.cn/news/1083691.html

相关文章:

  • 【BTC】协议(共识机制)
  • 自定义指令
  • java+vue+SpringBoo职业生涯规划系统(程序+数据库+报告+部署教程+答辩指导)
  • 【AI大模型】Spring AI 基于mysql实现对话持久存储详解
  • 多模态大语言模型arxiv论文略读(149)
  • 【网络协议安全】任务13:ACL访问控制列表
  • 深度学习图像分类数据集—蘑菇可食性识别分类
  • 使用Python将PDF转换成word、PPT
  • 量子计算机技术(第二节,到底什么是量子)
  • 【CSS-15】深入理解CSS transition-duration:掌握过渡动画的时长控制
  • 高速信号眼图
  • ASP.NET代码审计 Web Forms框架 SQL注入漏洞
  • 【Python】使用读取到的文件
  • 零成本搭建浏览器远程Linux桌面:Ubuntu/Debian方案全解析
  • MySQL数据库主从复制
  • python-if结构、三目运算符
  • 善用关系网络:开源AI大模型、AI智能名片与S2B2C商城小程序赋能下的成功新路径
  • 知识文档管理系统选型指南(中小企业专用)
  • CppCon 2018 学习:What Do We Mean When We Say Nothing At All?
  • 一文掌握Qt Quick数字图像处理项目开发(基于Qt 6.9 C++和QML,代码开源)
  • 计算机网络1.1:什么是Internet?
  • 电商系统二次开发找谁做?ZKmall开源商城前后端分离技术更易升级迭代
  • leetcode 每日一题 1865. 找出和为指定值的下标对
  • uniapp实现的多种时间线模板
  • Redis存储Cookie实现爬虫保持登录 requests | selenium
  • TCP/IP协议栈实现浅析(下) 报文接收相关函数及流程分析
  • 软件版本FCCU(故障采集与控制单元)设计
  • RS触发器Multisim电路仿真——硬件工程师笔记
  • Linux命令大全:按功能分类详解(附表格速查)
  • Altium Designer使用教程 第一章(Altium Designer工程与窗口)