White screen when launch TWA with splash - android

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.

Related

Load html in webview when app is in background

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.

How to make sure URL's are opened correctly in a progressive web app on android?

I have a meteor app running that can be added to homescreen on android. Doing this neatly installs the PWA. When I tap an URL in my system, the intent filter fires correctly and opens my app, but the thing is:
If my app is not open in the background, the intent fires correctly, opens my app and navigates to the correct URL.
If my app is open in the background the intent fires correctly and opens my app but doesn't navigate to the URL and the app just remains on the same page.
Any ideas as to how this is possible? Of course I want scenario 2 to also open the right URL directly.
I can't really control how the apk works on my phone because I believe chrome creates the apk when I use the "add to homescreen" function. I have setup the scope and start_url correctly in my webapps manifest.json. Perhaps I am missing a service worker I don't know about?

Android browser in background

I am developing a web page for android browser. The page will authenticate users. I placed an iframe that will refresh every 10 minutes to keep the user logging while the page is open. However if the user switch to another application placing the web browser in the background, the refresh to keep logged in stops. So when the user switch back to the browser the session is lost and errors pop up from my ajax call in that page.....
How could i handle this scenario when the browser is sent to the background and keep the session alive?
thanks
Your app will call the onPause() and then the onStop() method of your Activity when it loses focus.
If you want to make things work in the background, you will have to do this in a Service. There is just no better way of doing background tasks.

Android: Determine the previously displayed external Activity

In my application, I used a library that displays ads in my app. When a user clicks on the ad, it launches the Browser app, and the onClick events are handled by the library itself.
I also have a placed code in onPause() and onStart() methods that detects whether any of my Activities are sent to background (user pressed Home) or switching between any of my Activities.
So if the app is either freshly opened (no instance is running) or re-opened from background, it will display a dialog box. If the user is only switching from any of my Activites, then the dialog box shouldn't be displayed.
Now the problem is that when the user clicks on an Ad, the Browser app gets loaded and would mean that my App has been sent to background, and so when the user closes the Browser, it will still display the dialog box when it shouldn't.
Is it even possible for my App to determine the previously displayed external Activity (ie. Browser) and not display the dialog box?
Or are there better approaches that I can follow in implementing such setup?
Thanks in advance.
I don't think that there is a way for your Activity to know, which was the previous activity. A simple work-around is to save the time the dialog was displayed and not displayed it again, before some time passes. You can decide on the exact time period based on your application's requirements.
This may be in fact better in some situations. If the user switches from the Browser to your application and it has been some time he has used your application, it will be appropriate to show the dialog again.
you can use onResume() method to specify the behaviour when your activity get back from the background.

Android - WebView dies on resume

I have Activity with some data displayed in WebView that I load with WebView#loadDataWithBaseURL
Then I have/click menu option that fires android.content.Intent.ACTION_SEND
Choose email from the chooser
Google email comes up (as expected)
Discard email and hit back button
Action with WebView tries to resume
Bang - I get NullPonterException at line 4380 in WebView.java if (mWebViewCore.getSettings().getNeedInitialFocus()) since mWebViewCore is now null
The only place in code where mWebViewCore is nullified is at WebView#destroy - how do I recover from this? Do I need to recreate the browser and load my data all over again, that seems pretty wasteful? I really appreciate good suggestion at this point
Well, I can tell you that I just tested using a WebView with loadDataWithBaseURL(), where the page I loaded had a link. Clicking on the link brings up the Browser application, as expected. BACK button-ing out of the Browser brings back my app with the WebView just fine, no exceptions.
So, either ACTION_SEND/Gmail are somehow special, or there is something more going on with your app.
Can you replicate the problem in a small project that you can post somewhere?

Categories

Resources