当前位置: 首页 > 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.lryc.cn/news/581837.html

相关文章:

  • 【机器学习笔记Ⅰ】12 逻辑回归
  • get: ()=>state 和get: ()=>{state}
  • std::vector<bool>有什么特殊的吗
  • Podman与Docker详细比较:从原理到使用
  • 单片机总复习
  • 开关电源抄板学习
  • Spring Cloud Alibaba/Spring Boot整合华为云存储实例(REST API方式)
  • 反向遍历--当你修改一个元素的outerHTML时,该元素会被从 DOM 中移除
  • Python设计小游戏方法简介
  • 【C++】string类(二)相关接口介绍及其使用
  • 2025年03月 C/C++(四级)真题解析#中国电子学会#全国青少年软件编程等级考试
  • LeetCode 每日一题 2025/6/30-2025/7/6
  • WPF学习笔记(26)CommunityToolkit.Mvvm与MaterialDesignThemes
  • 端到端矢量化地图构建与规划
  • 【机器学习笔记 Ⅱ】1 神经网络
  • 从源码到思想:OneCode框架模块化设计如何解决前端大型应用痛点
  • RDF安装使用教程
  • 408第三季part2 - 计算机网络 - 传输层
  • 计算机网络实验——配置ACL
  • 植物大战僵尸杂交重制版1.0,经典焕新,重燃策略塔防之火
  • C 语言指针与作用域详解
  • 计算机网络实验——互联网安全实验
  • SQL Server从入门到项目实践(超值版)读书笔记 20
  • Solidity——什么是selfdestruct
  • 数据结构---链表结构体、指针深入理解(三)
  • nginx的使用
  • 机器学习手写字体识别系统:技术演进与应用实践
  • Qt:QPushButton、QRadioButton、QCheckBox
  • 1.1_4 计算机网络的分类
  • ARMv8 创建3级页表示例