iOS入门(ongoing)

Record it:

 

The overview of iOS you need to fast read:

 

https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/chapters/Introduction.html

 

First Step:

 

Object-C

https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html#//apple_ref/doc/uid/TP30001163

 

https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/chapters/WriteObjective-CCode/WriteObjective-CCode/WriteObjective-CCode.html

 

Someting new for Object-C

 

A protocol declares methods that can be implemented by any class, even if those classes implementing the protocol don’t have a common superclass.

 

From a practical perspective, a protocol defines a list of methods that establishes a contract between objects without requiring them to be instances of any specific class. This contract enables communication between those objects. One object wants to tell another object about the events it’s encountering, or perhaps it wants to ask for advice about those events.

 

A category is a feature of the Objective-C language that enables you to extend the interface of a class without having to subclass it. You can send a message to any instance of the class (or its subclasses) to invoke a method defined in the category.

 

When you want to call a method, you do so by sending a message to the object that implements the method. (Although the phrase "sending a message” is commonly used as a synonym for “calling a method,” the Objective-C runtime does the actual sending.) A message is the method name along with the parameter information the method needs (properly conforming to type). All messages you send to an object are dispatched dynamically, thus facilitating the polymorphic behavior of Objective-C classes. (Polymorphism refers to the ability of different types of objects to respond to the same message.)

 

https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/chapters/AcquireBasicProgrammingSkills/AcquireBasicSkills/AcquireBasicSkills.html

 

 

Cocoa:

https://developer.apple.com/library/ios/#documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/PortingfromCocoa/PortingfromCocoa.html#//apple_ref/doc/uid/TP40007898-CH8

 

在 Android 系统中,`PROMOTED_ONGOING` 是与进程优先级和任务调度相关的一个状态标识,通常用于描述某些具有较高重要性且需要持续运行的前台任务。该状态主要用于系统对应用进程进行资源管理和调度决策,确保关键任务获得更高的系统资源优先级。 ### 作用 `PROMOTED_ONGOING` 的核心作用是提升特定任务的优先级,使其更不容易被系统回收或降级。当一个任务或服务被标记为 `PROMOTED_ONGOING` 时,它会被视为正在进行的重要操作,从而影响系统的 OOM(Out Of Memory)调整策略。这种状态常见于需要保持活跃状态的任务,例如: - 长时间运行的前台服务 - 某些系统级操作(如备份、恢复等) - 与其他高优先级组件交互的关键任务 通过将任务标记为 `PROMOTED_ONGOING`,系统可以更好地判断哪些进程应当保留,避免因内存压力而被过早终止[^1]。 ### 使用场景 1. **前台服务**:当应用启动了一个前台服务(Foreground Service),系统可能会将其标记为 `PROMOTED_ONGOING`,以确保其不被轻易杀死,尤其是在资源紧张的情况下。 2. **系统关键任务**:一些系统组件在执行关键操作时会使用此状态,比如设备恢复出厂设置、OTA 升级过程中的数据迁移等。 3. **跨进程通信中的关键事务**:当某个任务正在等待来自另一个高优先级进程的结果时,系统可能将其提升为 `PROMOTED_ONGOING`,以防止其提前终止导致死锁或中断。 4. **Activity 启动过程中的中间状态**:在 Activity 启动过程中,如果涉及到多个组件的协同工作,系统可能会临时将某些进程标记为 `PROMOTED_ONGOING`,以保障启动流程顺利完成[^1]。 ### 示例代码片段 以下是一个简化的示例,展示如何在系统源码中检查一个任务是否被标记为 `PROMOTED_ONGOING`: ```java if ((taskInfo.flags & ActivityManager.LOCK_TASK_FLAG_PROMOTED_ONGOING) != 0) { // 任务已被标记为 PROMOTED_ONGOING Slog.d(TAG, "Task is promoted as ongoing"); } ``` 此类标志位通常由系统框架根据当前任务状态自动设置,并参与 OOM 调整策略的计算。 ### 进程优先级的影响 当进程被标记为 `PROMOTED_ONGOING` 时,它的 `oom_adj` 值会被调整为更低(即更高优先级),这使得它在内存不足时更不容易被 Low Memory Killer(LMK)机制杀死。这种调整机制有助于维持用户体验,特别是在执行关键操作期间[^1]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值