Load html in webview when app is in background - android

I have a webview which loads page from our local server and executes JS function. Everything works fine till the app goes background (Android 8 and above).
I use foreground service to keep the other features of the app running but the webpage does not load but JS function executes on an already open page.
The webview should be up-to-date when the app comes to foreground again.
This is a voice based application and contents on screen keeps updating as user progresses with his task.

Related

White screen when launch TWA with splash

I am showing a splash screen(TWA splash) when launching TWA, but I see a white screen for 4-5 seconds after the splash screen when launch the app after a delay, as my web code needs to load a lot more data before launch, I know my web code should not take too much time to load, but I want to handle this white screen with a loader on native end only due to some limitation.
I have not extended LauncherActivity(from android browser helper SDK) neither used it as a launcher in Manifest, I had copied code(whatever required) from this activity to my native activity Abc due to some conditional launch.
I am not able to figure out which activity is hosting web content now after the TWA launch. As my activity, Abc seems to be in an onPause state. so I can not use this activity to show loader. If I used a new activity to show a loader my web content does not load in the background, it starts loading only when web content is in the foreground.
I want to show loader when there is time to load web content, is there any way to do it?
Note: I have few redirects in my web URLs for launch.
The problem in this case is that the web application is taking too long to load.
The Splash Screen from the Trusted Web Activity will be started while Chrome is loading the page and will be automatically removed by the time the initial URL fires the pageload event.
There are several techniques you can use to improve the performance from your web application. A good place to get started is https://web.dev/fast/. One tip from your description is that the Trusted Web Activity should open the final URL and not have any redirects.

How to use service workers in android WebView?

I have created a PWA and I am opening it in the android app's WebView. The PWA opens in WebView, the service worker is also registered when the app is opened in online mode. But, when I open the app in offline mode I am not able to see ServiceWorker js file which was registered earlier. How to persist the ServiceWorker js file?
I went through Android's WebKit, there it was specified that for service worker support in WebView we need to use ServiceWorkerClient and ServiceWorkerController, but it is not clear, that, how exactly to use them with the WebView.
If you are looking for native intervention in service workers you can use the ServiceWorkerController but only on webview pages that have a service worker installed.
Please see this answer for a working example.

Run mobile web application in the background as a service

I am working on a HTML5 mobile web application that runs in browser. I want this app to receive server sent push notifications even when the browser/web app is closed. For that reason, I would want my mobile web app to run in the background once visited. I mean I will store some code on mobile maybe cache etc. So the question is that is it possible to run mobile web app as a service on mobile device?
Yes, in iOS, you can let your web application run in background (when it is closed). You have to give some settings to your application. However, in background, the UI threads is suspended, all commands in UI thread will be cached, until you open your application again. So remember to process your services in background threads, else they will be stucked with UI thread.
In Android, you can even create a service (without interface) and let it execute separately from your main application.
For another platform, I don't know the answer.
On iOS you can set a web page to run as a web app. There is even an SO tag for iphone standalone web apps, and the overview explains it nicely.
Here is the equivalent for Android - Add to homescreen

Background process stops when another page is open in phonegap android

I am trying to create an app in which i am using background serviced plugin for uploading data to server.Then i tried to go back to the app home page when a background service will start so the user can do other work while data is uploaded. but the issue is as soon as I click on the device back button it gives an network not found error and background service stops and it navigate to another page. Then i search how to navigate to device main page using device back button using home plugin know after starting the background service when i click on the back button it opens the device home-screen and the backgroung process continues. Can anyone tell me how to make an background serviced continue and navigate to another page.

Download video from AmazonS3 with ProgressBar in Android

Here i developed one application which download big size of videos from AmazonS3Bundle with HorizontalProgressBar but when i go to home screen by pressing home key and when i get back to my application's download screen, my download is restarting from beggining.
I want my application to keep downloading in background even if i go to any other application.
That's because your Activity's onCreate() gets called everytime and the task to Download gets started again.
You should make one Service class to do the download task, So it will keep doing it in Background irrespect of the state of the Application.
Check these two examples : first and second link

Categories

Resources