我有一些
WebView
小部件在我的
Activity
. 我用
loadData()
要设置内容,此HTML包含一个链接。我的一些
WebViews
工作正常,当我点击链接时,网络浏览器会在一个新的窗口中启动,但有些会使我的应用程序在点击链接时崩溃。
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
当我单击该URL时激发,但我对此没有控制权
意图
我想。
有人知道吗?
我用这个
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");
}
}