Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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? 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?

like image 577
Mr_E Avatar asked Nov 08 '22 04:11

Mr_E


1 Answers

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." 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.
  • 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!

like image 103
abielita Avatar answered Nov 15 '22 04:11

abielita