Make sure to look out for onPageFinished in order to complete the

I'm just starting out in programming and I've run into an issue with my webview code. In my implementation, I have a onPageFinished method with JavaScript logic inside to extract plain text from the webview. However, the onPageFinished method always completes after the main thread, preventing me from executing anything else afterward.

Is there a way for me to check if onPageFinished has finished or delay the main thread so it doesn't end before onPageFinished? I'm really in need of a solution.

Below is the code snippet:

WebViewActivityclass

public class WebViewActivity extends Activity{

String[] paraText;

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@SuppressLint("JavascriptInterface")
@Override
public void onCreate(Bundle savedInstanceState) {
    // Rest of your code here...
}

// Additional methods within the class...

}

Answer №1

After exploring various options, I managed to devise my own solution;

As discussed here, it is advised against making a UI thread sleep as it can cause all activities to be paused. Instead, the use of handler postDelay is recommended.

Here is the code for the solution:

 Handler handler = new Handler();
 handler.postDelayed(new Runnable(){
  @Override
  public void run(){
  // perform action
    }
  }, 3000);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Experience the combined power of addthis, isotope, and nicescroll - all in a single

I am utilizing a WordPress template that includes a set of share buttons from AddThis. <ul class="addthis extra"> <li class="addthis-hold"> <div class="addthis_toolbox" addthis:url="<?php the_permalink( ...

Creating a custom hook in React that utilizes the useEffect hook with asynchronous functions

I am encountering an issue with my customHook that utilizes useEffect where I want it to return a result only after useEffect has completed. However, it consistently returns before my async method finishes... // customHook const useLoadData = (startLoading ...

Using Android to retrieve and process JSON data for display in a list view

I have a current android project where I am trying to implement a functionality that allows me to display user data into a listview on another activity by pressing only one button. Currently, my solution involves pressing two buttons - one to retrieve JSON ...

Populating arrays with prompts using javascript

I'm currently working on a task that involves prompting the user to input random numbers until they enter "-1". Once this condition is met, I need to calculate the average of all the numbers entered excluding "-1". So far, here's what my code loo ...

Deploying archives for both debug and release builds

My gradle script includes an upload task: uploadArchives { repositories { mavenDeployer { repository(url: "${nexusUrl}/content/repositories/apps-releases") { authentication(userName: nexusUsername, password: ...

Passing data back from an asynchronous function to its parent function in Node.js

Exploring the world of asynchronous programming is a new adventure for me as I delve into implementing Twilio video calls through Node.js. I've been grappling with calling a server-side function that in turn invokes another asynchronous function retu ...

Troubleshooting problem with radio button selection when integrating Map functionality

I am currently working with an array list that I am rendering using the map function. Each object in the array includes a radio button. However, when I click on the radio button for a specific data entry, I encounter an error message saying "TypeError: Can ...

Having trouble getting the Underscore.js template to function correctly with JSON data

Hello there! I have some PHP code $arr = array("title"=>"sample Title", "body"=>"151200"); echo json_encode($arr); The data output is: {"title":"test Title","body":"151200"} When I attempt to use this JSON output in Underscore, I encounte ...

"Presenting Invoice Information on an Invoice Template: A Step-by-Step Guide

Currently, I am working with Laravel 5.7 and VueJs 2.5.*, where I have a table of invoices. My goal is to create a new component that will display a specific invoice based on user selection, allowing them to view or print the chosen invoice. I am still ex ...

A possible invocation of a function using a JavaScript "class"

Presented here is a node module I've been working on: var _ = require('lodash'); function Config(configType, configDir) { this.configType = configType; this.configDir = configDir; }; Config.prototype.read = function() { // read file t ...

converting JSON to date format in angular

.controller('feedCtrl', ['$scope', '$http', function($scope, $http) { $http.get('items.json').then(function(response) { $scope.items = response.data; $scope.user = localStorage.getItem("glittrLoggedin"); ...

What could be the reason my spin animation is only triggered once upon button press?

Every time the submit button is clicked, I want all the images to spin. However, this rotation effect only works the first time the button is pressed, until the page is refreshed. I have used jQuery to add and remove a class from the images when the button ...

Error: The variable "$this" has not been defined in the AJAX function

Recently, I've been delving into the world of javascript and ajax. I'm trying to create a dynamic select option list similar to this: https://i.sstatic.net/qELIf.png However, when attempting to compile using Google Chrome Developer tools (F12), ...

What causes the original array to be altered when copying its contents into another array?

After transferring a 2D array into another temporary array, I notice that any operations performed on the temporary array end up altering the original one as well. To illustrate my point, here is part of the code snippet: public int getPossibleMoves(int ...

Creating sophisticated TypeScript AngularJS directive

Recently, I came across a directive for selecting objects from checkboxes which can be found at this link: The issue I'm facing is that we are using TypeScript and I am unsure of how to implement the directive in TypeScript. From what I understand, ...

Setting a specific time zone as the default in Flatpickr, rather than relying on the system's time zone, can be

Flatpickr relies on the Date object internally, which defaults to using the local time of the computer. I am currently using Flatpickr version 4.6.6 Is there a method to specify a specific time zone for flatpickr? ...

I'm having trouble locating the airtable module, even after I successfully ran npm install airtable

Currently attempting to integrate the airtable api into my website's backend using node.js. However, upon writing var Airtable = require('airtable'); and running the file with node [filepath], I encounter an error in the command prompt: ...

Issue of Vue not resolving Ionic back button component

I'm having trouble figuring out why Vue is giving me a warning and the back button isn't functioning as expected: runtime-core.esm-bundler.js?5c40:38 [Vue warn]: Failed to resolve component: ion-back-button at <TheHeader titulo="Home&q ...

Display elements conditionally based on the result of an asynchronous operation within an ng

Using Angular version 11.0.2 I am encountering issues with the async pipe inside an ngIf template, where my data is not being properly refreshed. To illustrate this problem, I have created a simplified example. View code on Plunker To reproduce the issu ...

Guide on viewing chromedriver logs during Protractor testing

I've recently discovered that chromedriver has the ability to generate a logfile (https://sites.google.com/a/chromium.org/chromedriver/logging) While the process of setting up this feature when running the executable directly is clear: chromedriver. ...