我是學習java的新手。我一直在努力工作2天。我會生氣的。請幫我在webview中等待javascript完成以繼續Android Java
我希望當我的函數運行時,所有的活動都必須等到我的函數完成。
示例
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代碼,但我無法在async服務器中使用webview。
我把webview裏面的rununithread()裏面的asynctask,我不能再做。
我試着把Count_Timer()放到CountdownTimer裏面,但是在CountdownTimer完成之前運行了「oncreate finished」這一行。
現在我感到無助。我不知道java或android編程這麼多。我是php程序員。我嘗試做webview應用程序。我不太瞭解Java結構。如果你能做到,你能寫出正確的示例工作代碼嗎?因爲我不明白所有的例子。我看了,看了一切,也許有解決辦法,但我無法理解。我需要你的幫助。
感謝
? –