gpt4 book ai didi

android - 如何通过处理程序从 IntentService 多次调用 WebView Activity ?

转载 作者:行者123 更新时间:2023-11-30 04:16:06 25 4
gpt4 key购买 nike

我有一个 IntentService 正在解析一些 xlm 文件以创建一个 html 文件。我已经完成了使用一些模板创建该 html 文件的工作。但问题是我需要为我从文件中解析的每个“媒体”节点更改该 html 文件。然后根据新的传入类型,我必须创建一个新的相应 html 文件以通过 WebView 查看。

到目前为止,我尝试创建一些处理程序并将 Intent 传递给 WebView 类。 (我没有通过 bundle 发送任何数据。我只是在我的服务类中创建该 html 文件,然后从 WebView 调用该文件。)这种想法第一次起作用。但是,在第一个媒体结束后,我无法第二次调用相同的 Activity 。调用 WebView 的代码如下:

if(counter == 0){
createDir(); //function to create html file with corresponding date
Intent sender = new Intent(getApplicationContext(), webLoader.class);
//System.out.println("here");
sender.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(sender);
}
else
{
//System.out.println("entering?");
System.out.println(durationOfMedi);

new Handler().postDelayed(new Runnable() {

public void run() {
// TODO Auto-generated method stub
try {
createDir(); //function to create html file with corresponding date
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Intent sender = new Intent(getApplicationContext(), webLoader.class);
sender.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(sender);
}
}, durationOfMedi*1000);
}

我基本上想做的是,我遍历每个媒体项并根据它们的值等。我在 IntentService 中创建另一个 html 文件,然后我尝试启动我的 WebView Activity 以查看该 html文件。这些媒体项目中的每一个都有一定的持续时间可以在屏幕上看到,所以这就是为什么我在第一个媒体之后使用 postDelayed 并且我用一些变量“计数器”来跟踪它的原因。(对于第一个媒体我直接创建文件并显示它但是之后我等待了一段时间“durationOfMedi * 1000”毫秒。)但是在第一个媒体之后它没有工作。它只是通过 html 文件将该项目加载到屏幕,然后它不会进入 new Handler()... 方法。如果有人可以帮助我,我将不胜感激。我对此一无所知。

最佳答案

我通过直接让当前线程休眠一段时间来实现这种情况,这样做是这样的:

if(counter == 0){
Thread.sleep(1000*previousDuration);
createDir();
Intent sender = new Intent(getApplicationContext(), webLoader.class);
sender.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(sender);
}

通过应用那种方法,我可以触发其他 Activity 。并且为了避免堆栈上的任务过多,我还包括:

android:noHistory = "true"

在我的 list 文件中。那完成了工作。如果有人遇到这种情况,我会发布这个。

关于android - 如何通过处理程序从 IntentService 多次调用 WebView Activity ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9992837/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com