日期:2014-05-16  浏览次数:20872 次

windows phone因为墓碑化导致“正在恢复”的分析

我们在平时的WP使用过程中,会遇到一个问题

应用在切出,切回后,

  1. 有时候,会显示“正在恢复”,并等待时间较长,才能回到用户切出时候的画面,但是这种情况并非常见,偶尔发生
  2. 有时候,直接回到切出时的画面,反应还蛮迅速的

这是为什么那?

我做了研究,分析如下:

首先,我们看一下WP的生命周期

(详情见:App activation and deactivation for Windows Phone 8)


当应用因为
  1. 用户点击WIN键
  2. 发送短信,跳往WIFI设置,或者其他Task

切出应用后,会触发事件Deactivated,失活,也就是不在前台显示了

然后,

这里是关键

存在两个状态

  1. Dormant
  2. TomeStoned

Dormant

When the user navigates forward, away from an app, after the Deactivated event is raised, 
the operating system will attempt to put the app into a dormant state. 
In this state, all of the application’s threads are stopped and no processing takes place, 
but the application remains intact in memory. If the app is reactivated from the dormant, 
it doesn’t need to do anything to re-establish state, because it has been preserved.

If new apps are launched after an app has been made dormant, 
and these applications requires more memory than is available to provide a good user experience, 
the operating system will begin to tombstone dormant applications to free up memory.

休眠

当用户向前导航或导航出应用时,引发 Deactivated 事件后,操作系统将尝试使应用置于休眠状态。在此状态下,应用程序的所有线程均将停止,并且不进行任何处理操作,但应用程序仍完好地保留在内存中。如果应用是从休眠状态重新激活的,则无需执行任何操作来重建状态,因为状态已被保留。

如果在应用进入休眠状态后启动新的应用,这些应用需要更多的内存才能提供出色的用户体验,操作系统将开始逻辑删除休眠的应用以释放内存。


Tombstoned

A tombstoned app has been terminated, but the operating system preserves information about its navigation state 
and also preserves the state dictionaries the app populated during Deactivated. 
The device will maintain tombstoning information for up to five apps at a time. 
If an app is tombstoned and the user navigates back to the application, 
it will be relaunched and the application can use the preserved data to restore state.

已逻辑删除(即墓碑化)

已终止逻辑删除的应用,但操作系统不仅保留了有关其导航状态的信息,而且还保留了 Deactivated 期间填充应用的状态字典。设备每次最多可维护五个应用的逻辑删除信息。如果在逻辑删除应用之后,用户向后导航至应用程序,则应用程序将会重新启动并使用保留的数据还原状态。

回到问题


应用在切出,切回后,

  1. 有时候,会显示“正在恢复”,并等待时间较长,才能回到用户切出时候的画面,但是这种情况并非常见,偶尔发生
  2. 有时候,直接回到切出时的画面,反应还蛮迅速的

我认为,

这是因为两种不同的状态返回了应用而致:

应用是从休眠状态重新激活的,则无需执行任何操作来重建状态,因为状态已被保留。

于是这样发生了2