当前位置: 首页 > 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.dtcms.com/a/268108.html

相关文章:

  • 网安系列【7】之文件上传漏洞
  • 云服务器环境配置——安装Tomcat
  • Redis集群部署指南:高可用与分布式实践
  • 网关多次读取流问题
  • 老树新花语新颜,汉字筑渠话情流——与ai助手闲聊成诗(智普清言)
  • 程序员在线接单
  • Python设计小游戏方法简介
  • SpringBoot基于Mysql的商业辅助决策系统设计与实现
  • Web前端开发-Vue
  • 【网络安全基础】第九章---IP安全
  • unix环境编程试题
  • 平台设备总线相关概念(RK3588)
  • 多模态大模型推理技术突破:从 CoT 数据到 RL 优化,AI 推理如何征服复杂任务?
  • 开源!RAG竞技场(2):标准RAG算法
  • 编程语言艺术:C语言中的属性attribute笔记总结
  • RPC/gRPC入门学习
  • GM DC Monitor和WGCLOUD,能比吗?
  • 深入理解原子类与CAS无锁编程:原理、实战与优化
  • 【大模型LLM】 Megatron-LM 大模型训练框架吞吐率计算吞吐率优化策略
  • Rust实战:中医丹方智能管理系统
  • ipmitool 使用简介(ipmitool sel list ipmitool sensor list)
  • WebRTC 的 ICE candidate 协商
  • 【卫星语音】基于神经网络的低码率语音编解码(ULBC)方案架构分析:以SoundStream为例
  • 开关电源抄板学习
  • linux chrome浏览器打不开了
  • 线程——基础全解
  • 第一个Flink 程序:词频统计 WordCount(流处理)
  • Peek-Ubuntu上Gif录制工具-24.04LTS可装
  • rxcpp--composite_subscription
  • Kotlin lazy 委托的底层实现原理