简体   繁体   English

Android上安装的Progressive Web App的生命周期是什么?

[英]What is the lifecycle of an installed Progressive Web App on Android?

I have a strong Android background but I have recently developed a PWA that can be installed to a users device. 我有一个强大的Android背景,但我最近开发了一个可以安装到用户设备的PWA。 I have noticed that when the app starts for the first time, the splash screen shows and then the app displays it's first page which is great. 我注意到,当应用程序第一次启动时,启动屏幕显示,然后应用程序显示它的第一页很棒。 Now, if the app has been backgrounded for a while and I relaunch the app, it sometimes appears to display a white screen for a few seconds then the app kind of flickers and some aspects of the page reload, creating a jarring experience. 现在,如果应用程序已经搁置一段时间并重新启动应用程序,它有时会显示白色屏幕几秒钟然后应用程序类型的闪烁和页面的某些方面重新加载,创建一个不和谐的体验。

I am familiar with how lifecycles work in Android, saveInstanceState and all that jazz, but what is actually happening here with a PWA is backgrounded? 我熟悉生命周期在Android,saveInstanceState和所有爵士乐中的运作方式,但是PWA实际发生的事情是背景的吗? I am unable to debug what is happening because it takes a long time to reproduce and the debugger needs to be attached before launching the app. 我无法调试正在发生的事情,因为它需要很长时间才能重现,并且在启动应用程序之前需要附加调试器。

Are there any documents describing exactly what is happening with the lifecycle of an installed PWA and how to gracefully restore it when it has been backgrounded or background-killed? 是否有任何文档准确描述了已安装的PWA的生命周期发生了什么,以及如何在它背景化或背景杀死时优雅地恢复它?

You may look into this documentation . 您可以查看此文档 "Progressive Web Apps have to be fast, and installable, which means that they work online, offline, and on intermittent, slow connections. To achieve this, we need to cache our app shell using service worker, so that it's always available quickly and reliably." “渐进式Web应用程序必须快速,可安装,这意味着它们可以在线,离线以及间歇性,慢速连接。要实现这一点,我们需要使用服务工作人员缓存我们的应用程序shell,以便它始终可用,并且可靠“。 A service worker has a lifecycle that is completely separate from your web page. 服务工作者的生命周期与您的网页完全分开。 Based from this article , a service worker lifecycle usually has three stages: 根据这篇文章 ,服务工作者生命周期通常有三个阶段:

  • The install stage , during which it is common to cache assets like stylesheets, client-side JavaScript, and so on. 安装阶段 ,在此期间通常会缓存样式表,客户端JavaScript等资产。
  • When the install stage was successful, the activation step happens, during which any obsolete caches are deleted. 安装阶段成功后,将执行激活步骤 ,在此期间将删除任何过时的高速缓存。
  • Then, the service worker is idle until it needs to deal with a request from the client code. 然后,服务工作者空闲,直到它需要处理来自客户端代码的请求。

You may read the article for more information. 您可以阅读该文章以获取更多信息。 Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM