我的Activity
內有一些WebView
小部件。我使用loadData()
來設置內容,並且這個html包含一個鏈接。我的一些WebViews
工作正常,當我單擊鏈接時,Web瀏覽器在新窗口中啓動,但有一些會在我點擊鏈接時使應用程序崩潰。單擊鏈接時Android WebView崩潰
10-13 08:45:24.257: ERROR/AndroidRuntime(751): Uncaught handler: thread main exiting due to uncaught exception
10-13 08:45:24.308: ERROR/AndroidRuntime(751): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at android.app.ApplicationContext.startActivity(ApplicationContext.java:627)
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at android.content.ContextWrapper.startActivity(ContextWrapper.java:236)
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:185)
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:277)
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at android.os.Handler.dispatchMessage(Handler.java:99)
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at android.os.Looper.loop(Looper.java:123)
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at android.app.ActivityThread.main(ActivityThread.java:3948)
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at java.lang.reflect.Method.invokeNative(Native Method)
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at java.lang.reflect.Method.invoke(Method.java:521)
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
10-13 08:45:24.308: ERROR/AndroidRuntime(751): at dalvik.system.NativeStart.main(Native Method)
似乎有與Intent
的WebView
火災時,我點擊的網址有問題,但我沒有這個Intent
的控制,我想。
有沒有人有什麼想法?
我用這個AsyncTask
設置在WebView
的內容,並能正常工作:
public class SetAdTask extends AsyncTask<Void, Void, String>{
private Main main;
private WebView webView;
public SetAdTask(Main main, WebView webView){
this.main = main;
this.webView = webView;
}
protected void onPreExecute() {
Main.Log("onPreExecute()");
}
protected String doInBackground(Void... params) {
Main.Log("doInBackground()");
return main.getRestClient().getAdCode();
}
protected void onPostExecute(String result) {
Main.Log("onPostExecute()");
String html = "<html><head><title>ad</title></head><body>";
html += "<div style=\"color:grey;font-size:12px;\">ADVERTISEMENT<br/>";
html += result;
html += "</body></html>";
webView.loadData(html, "text/html", "latin-1");
}
}
哦,我發現了問題..我已經啓動了與錯誤的上下文的webView ...我用viewView =新的WebView(main.getApplicationContext())...似乎webview呈現OK,與此上下文,但不能正確處理意圖... T – 2009-10-13 09:16:27
你可以回答你自己的問題,你知道的。 – 2009-10-13 19:27:16