注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

xu3stones的技术博客

OS >> Virtualization >> Cloud

 
 
 

日志

 
 

iphone IOS后台程序的管理 [转]  

2013-03-14 15:20:51|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

There is one iOS "tip" that I keep hearing and it is wrong. Worse, I keep hearing it from supposedly authoritative sources. I have even heard it from the lips of Apple "Geniuses" in stores.

Here is the advice - and remember it is wrong:

All those apps in the multitasking bar on your iOS device are currently active and slowing it down, filling the device's memory or using up your battery. To maximise performance and battery life, you should kill them all manually.

Wrong. Wrong. Wrong. Wrong. Wrong. Wrong. Wrong. There are caveats to this but anyone dispensing the advice above is clearly uninformed enough that they will certainly not be aware of these subtleties.

Let me be as clear as I can be: the iOS multitasking bar does not contain "a list of all running apps". It contains "a list of recently used apps". The user never has to manage background tasks on iOS.

Except in a few cases, which I'll explain, the apps that appear in the multitasking bar are not currently running. When you press the home button, iOS will tell the app to quit. In almost all cases, it quits, it stops using CPU time (and hence battery) and the memory it was using is eventually recovered if required.

Let's get technical: iOS apps have five states of execution. These are:

  • Not running - the app has been terminated or has not been launched.
  • Inactive - the app is in the foreground but not receiving events (for example, the user has locked the device with the app active)
  • Active - the normal state of "in use" for an app
  • Background - the app is no longer on-screen but is still executing code
  • Suspended - the app is still resident in memory but is not executing code

Active and Inactive are not interesting for this discussion. Most of the confusion is around what happens as an app goes from Active to Background to Suspended to Not Running.

When you press the home button, the app moves from Active to Background. Most apps usually then go from Background to Suspended in a matter of seconds.

The first technical caveat is that Suspended apps remain in the device's memory. This is so they can resume more quickly when you go back to them. They're not using processor time and they're not sucking battery power.

You may think that, if an app is resident in memory, you have to somehow remove it to conserve memory. You don't because iOS does it for you. If there are Suspended apps lying around and you launch a memory-intensive app such as a big game, iOS will start to purge Suspended apps and move them to the Not Running state. That is, they will be completely removed from memory and will launch afresh the next time you tap their icon.

Where some people get confused is this: all of the above has no impact on what you see in the multitasking bar. The multitasking bar always shows a list of recently used apps, regardless of whether they're in the Background, Suspended or Not Running states. You may also have noticed that the app that is currently Active does not appear in the multitasking bar.

Background Tasks

When an app is sent to the Background, it usually moves to the Suspended state in a few seconds. An app can request an extension to this by declaring that it's starting a "background task".

A good example is an app that downloads largish files from the web such as Instacast, my favourite podcast app. When Instacast is Active, it can start to download new podcasts. If I then hit the home button on my iPhone, Instacast gets five seconds to run in the Background state and then it's Suspended. That interrupts the download of my podcasts, which might take 5 minutes or more.

iOS allows Instacast to declare that a download is a "background task". This allows Instacast an extra period of background running after I hit the home button to complete the podcast download. While apps can request additional Background time, that time is not infinitely long. The app gets about 10 minutes of Background running time and then it is forcibly suspended by iOS. Again, you don't have to worry about this yourself.

Indefinite Background Running

All apps get 5 seconds of Background running. Some apps can request a 10-minute extension. There are a small number of apps that genuinely need to run indefinitely in the background and iOS allows this.

There are exactly five kinds of apps allowed to run indefinitely in the Background state in iOS 5:

  • Apps that play audio while in the Background state. A good example is Instacast while it's playing a podcast.
  • Apps that track your location in the Background. For example, you still want voice prompts from your TomTom navigation app, even if another app is Active.
  • Apps that listen for incoming VOIP calls. If you use Skype on iOS, you can receive incoming Skype calls while the app is in the Background.
  • Newsstand apps that are downloading new content.
  • Apps that receive continuous updates from an external accessory in the Background.

All well-written apps in the above categories should become Suspended when they are no longer performing the task in hand. When Instacast finishes playing a podcast, it should be Suspended. There are some built-in apps that also run continuously in the background on iOS - the most-used one is probably Mail.

As long as these apps are running in the Background state, they will consume memory, CPU time and power. In general, though, you would know that you were using such apps. The developer has to declare which category of Background running they require and part of the App Store review process is to check that these declarations are not being abused.

I said earlier that "the user never has to manage Background tasks on iOS". The only exception to this is when one of these Background-running apps goes berserk and will not terminate properly. That, however, is an exceptional situation and not a normal part of being an iOS user.

Summary

Let me wrap this up by giving you a quick summary:

  1. If someone tells you that all the apps in the multitasking bar are running, using up memory or sucking power, they are wrong.
  2. When you hit the home button, an app moves from Active to Background and quickly to the Suspended state where it no longer uses CPU time or drains power.
  3. An app may request an additional 10 minutes of Background running to complete a big task before becoming Suspended.
  4. If memory is becoming scarce, iOS will automatically move Suspended apps into the Not Running state and reclaim their memory.
  5. Five classes of apps - audio, GPS, VOIP, Newsstand and accessory apps - and some built-in apps such as Mail may run indefinitely in the background until they complete their task.

Put simply: you do not have to manage background tasks on iOS. The system handles almost every case for you and well written audio, GPS, VOIP, Newsstand and accessory apps will handle the rest.


翻译版:


大概常听到一些建议,要你关掉后台中的应用程序,来释放内存或还可以节省电力、让效能更好、让程序跑起来不会顿顿的...

而这基本上,这是错误的!

开发人员Fraser Speirs 这两天在 Blog 发表了一篇文章 "Misconceptions About iOS Multitasking", 就提到了许多使用者(甚至是Apple Store 里Genius Bar 的客服人员) 对于iOS 的多工处理作业有着不甚清楚或不正确的观念。


建议所有iOS 装置的使用者都可以阅读该篇文章,实际了解一下iOS 中所谓的「后台进程」到底是怎么回事!

原文:Let me be as clear as I can be: the iOS multitasking bar does not contain "a list of all running apps". It contains "a list of recently used apps". The user never has to manage background tasks on iOS.

【了解后台】

首先我们得搞清楚的是,iOS 中所谓的「后台驻留」并不是指「执行中的程序」,而是「最近使用过的程序」,也可以瞧瞧Apple 的知识库文章怎么写的:

按两下主画面按钮,显示最近用过的应用程序。

按两下主画面按钮后,显示的是「最近用过的应用程序」,所以别把它想成Mac OS X 中的Command + Tab 键所显示的切换程序列;你可以试试看将iPhone 关机再开机,然后按两下Home 键,应该会发现先前那些程式还是出现在那里,因为它其实是你最近使用过的程序使用记录,或像是浏览器中的浏览记录)。

如果你一个一个去清除 "后台驻留" 的程序,就像是一笔一笔删除浏览记录中的项目一样,是没有太大意义的(除非你不想让其他人看到你曾经用过什么程式,或者想杀时间、太无聊了),也不会对电力或记忆体有什么帮助。

iOS 的多工处理其实是很聪明的,系统会自动中止在背景执行的程序,在有需要时,也会将被中止的程式(suspended) 从内存中移除。因此,iOS 装置的使用者根本就不需要担心怎么「管理」这些执行中或不在执行中的程序,尽管放心用、轻松玩就是了!

一般说来,所有程式进入背景后都还有5 秒的执行缓冲时间,有些程序可以要求延长到10 分钟(这些当然是由开发人员在设计与提交程式时决定和声明);

因此,在你按下Home 键后,本来的程式就会退到背景,如果它有额外的背景执行作业,超过10 分钟还是会被iOS 中止;所以,还是别担心了!

但是,Fraser 也提到了例外情况,某些特殊类型的程式是被容许在背景中持续执行的,像是会持续在背景播放音乐的程序、GPS 程序、VOIP 程序、Newsstand 以及周边配件附属的程序,不过只要这些程序不再执行动作,就会变成中止的程式,像是音乐拨完了、杂志下载完了... 因此,使用者其实也没必要太过留意这些程序。

you do not have to manage background tasks on iOS. The system handles almost every case for you and well written audio, GPS, VOIP, Newsstand and accessory apps will handle the rest.

无论你是iOS 装置的新手、老手,甚至是店面销售或客服人员,Fraser 的结论请牢记在心。

  评论这张
 
阅读(198)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017