java - 如何在特定时间段后将新 url 加载到 web View 中?

标签 java android webview

我有一个模型的数组列表,其中包含---> key : { link : ... , duration : .... }。 在我的数组列表中存在的所有链接之后,我需要加载我的 android web View ,并在特定的持续时间内加载它们。

更新:

我尝试了处理程序,但它仍然加载最后一个网页并使 Thread.sleep() 挂起应用程序

最佳答案

您可以使用特定时间间隔的 timerTask 来加载您的列表 url

 private static Timer timer;
    private TimerTask timerTask;

    public void startTimer() {
        //set a new Timer
        try {
            timer = new Timer();
            //initialize the TimerTask's job
            initializeTimerTask();

            //schedule the timer, to wake up every 2 second
            timer.schedule(timerTask, AppConstants.bgTaskStartDelay, 2000); //
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

 // it sets the timer to print the counter every x seconds
public void initializeTimerTask() {
    timerTask = new TimerTask() {
        public void run() {
            try {
               // you code here to load url from your array

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
}

关于java - 如何在特定时间段后将新 url 加载到 web View 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58498343/

相关文章:

java - Android webview 应用程序不会加载我的表单

javascript - react native html postMessage 无法到达 WebView

visual-studio - 如何在Visual Studio工具栏中添加WebView2控件?

android - 将 admob 广告放在 webview 的底部

java - apache.commons.exec - 吞下执行进程抛出的异常?

java - 图像不显示 Android Java

android - 什么样式/attr/drawable 用于反背景?

android - 为什么我需要在 Android Lollipop 上使用 getExternalCacheDir() 的 WRITE_EXTERNAL_STORAGE 权限?

c# - 在java中使用C# dll

java - 不断监听端口