【发布时间】:2016-11-08 02:19:52
【问题描述】:
我是学习 java 的新手。我一直在努力如何才能做到 2 天。我会生气的。请帮帮我
我希望当我的函数运行时,所有活动都必须等到我的函数完成。
一个例子
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
webView2 = (WebView) findViewById(R.id.webView);
Log.v("htmlg","oncreate started");
main_command();
/*
*
* main_command(), When this command run application must wait in here.
*
* */
Log.v("htmlg", "oncreate finished");
}
公共静态 int 完成 = 0;
public void main_command(){
/*
*
* There is some webview actions in here. it takes about 5 minutes.
*
* When webview operations are finished.
* I call javascript command javascript:window.HTMLOUT.ok();
* I want everything wait until webview operations are finished and javascript command runned.
*
* */
}
但我没有办法做到这一点。当 main_command() 运行时,Log.v() 函数将立即运行。但 main_command() 仍在运行且尚未完成。当它完成时,一个javascript命令将调用android内部的一个函数。然后过程将完成,应用程序可以继续在原处工作。
现在,我来说说我的经历。
我尝试在 Asynctask 中编写 webview 代码,但无法在 asynctask 中使用 webview。
我把 webview 放在 asynctask 中的 rununithread() 里面,我不能再这样做了。
我试图将 main_command() 放入 CountdownTimer,但在 CountdownTimer 完成之前运行了“oncreate finished”行。
现在我感到很无助。我不太了解java或android编程。我是php程序员。我尝试做 webview 应用程序。我不太了解java结构。如果你能做到,你能写出正确的示例工作代码吗?因为我不明白所有的例子。我查看并阅读了所有内容,也许有解决方案,但我无法理解。我需要你的帮助。
谢谢
【问题讨论】:
-
你想停止你的用户界面或你的代码运行吗?
标签: java android multithreading webview countdowntimer