我注意到 StrictMode 正在大声抱怨 WebView 创建。有什么方法可以提高 WebView 对象的启动性能?我在 onCreate() 方法中从 XML 实例化。
webView = (WebView) findViewById(R.id.webview);
webView.clearCache(true);
webView.getSettings().setDefaultFontSize(20);
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new MyWebViewClient());
WebSettings wb = webView.getSettings();
wb.setRenderPriority(WebSettings.RenderPriority.HIGH);
webView.setWebChromeClient(new MyWebChromeClient(this));
这是许多 StrictMode 警告中的第一个:
D/StrictMode(22781): StrictMode policy violation; ~duration=1869 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2
D/StrictMode(22781): at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:745)
D/StrictMode(22781): at android.database.sqlite.SQLiteStatement.simpleQueryForLong(SQLiteStatement.java:106)
D/StrictMode(22781): at android.database.sqlite.SQLiteDatabase.getVersion(SQLiteDatabase.java:928)
D/StrictMode(22781): at android.webkit.WebViewDatabase.getInstance(WebViewDatabase.java:196)
D/StrictMode(22781): at android.webkit.WebView.<init>(WebView.java:1002)
D/StrictMode(22781): at android.webkit.WebView.<init>(WebView.java:979)
D/StrictMode(22781): at android.webkit.WebView.<init>(WebView.java:969)
D/StrictMode(22781): at java.lang.reflect.Constructor.constructNative(Native Method)
D/StrictMode(22781): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
D/StrictMode(22781): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
D/StrictMode(22781): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
D/StrictMode(22781): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
D/StrictMode(22781): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
D/StrictMode(22781): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
D/StrictMode(22781): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
D/StrictMode(22781): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
D/StrictMode(22781): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
D/StrictMode(22781): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:214)
D/StrictMode(22781): at android.app.Activity.setContentView(Activity.java:1660)
D/StrictMode(22781): at com.myapplication.StartActivity.onCreate(StartActivity.java:886)