On iOS, When is Platform.Ready fired vs. Resume?

允我心安 提交于 2019-12-13 20:47:45

问题


I know that platform.ready will fire when an app is loaded, and platform.resume will fire when the app is opened after being paused.

But, is there a certain amount of time of the app not being in use where the app will load instead of resume? If so, what is that amount of time for iOS and Android?

Can't seem to find any information on this and would love to understand this, thanks!


回答1:


TLDR: Typically we will receive a resume event, if an app comes from the background.

If the OS is running out of memory it might completely purge an app and we will receive the deviceready event. I'm not aware that there is any time limit after an app gets terminated by the OS, this should only happen, if the OS is running out of memory, is being restarted or the app is terminated manually by the user.


Okay let's see the typical lifecycle of a Cordova app by looking at the event docs:

  1. The user starts an app and the deviceready event is fired once Cordova is fully loaded
  2. If the user switches to another app, the native platform puts the application into the background and the pause event fires.
  3. If the user comes back to our app, the app will be put in the foreground by the native platform again. That's the moment when the resume event fires.

To answer your actual question, we will have to look at the implementation per native platform. First of iOS.

iOS apps have following execution states (Source: developer.apple.com):

So an app that is put in background will be put to in Background mode, which is described like this:

The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. ...

Assuming our app does not run in background/request extra execution time will only stay in this mode briefly and then be put into Suspended mode.

The Suspended mode is described like this (emphasis is mine):

The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code.

When a low-memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.


Pretty much the same applies to Android. The lifecycle of Android activities is little more complex, you can look up the details on developer.android.com. The bottom line is the same as for iOS (Source):

The system kills processes when it needs to free up RAM

So if the OS is running out of memory it might completely purge our app and our lifecycle will start from the beginning with the deviceready event. I'm not aware that there is any time limit after an app gets terminated by the OS, this should only happen, if the OS is running out of memory, is being restarted or the app is terminated manually by the user.



来源:https://stackoverflow.com/questions/50512973/on-ios-when-is-platform-ready-fired-vs-resume

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!