title: Inflating WebView is slow since Lollipop
body: <p>In fact I am surprised that I found no similar question in Stackoverflow, but I really can't figure it out.</p>
  
  <p><strong>First of all, please be reminded that this is not related to the performance of browsing webpage inside a WebView. It is only about inflating even an empty WebView, without loading any URL.</strong></p>
  
  <p>To eliminate all other factors, I have created a brand new project which contains things only necessary to reproduce the problem.</p>
  
  <p>In this almost empty project, I have a layout which contains only a <code>WebView</code>:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.testing.WebViewOnlyActivity"&gt;
  
      &lt;WebView
          android:id="@+id/webview"
          android:layout_width="match_parent"
          android:layout_height="match_parent"/&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>And I have a <code>MainActivity</code> which contains only a <code>Button</code> which starts this <code>WebViewOnlyActivity</code>:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent intent = new Intent(MainActivity.this, WebViewOnlyActivity.class);
                  startActivity(intent);
              }
          });
      }
  }
  </code></pre>
  
  <p>Simple enough, right?</p>
  
  <p>Now, when I build the project, click the button, the <code>WebViewOnlyActivity</code> takes <strong>more than 1 second to popup</strong>. But then if I press back button, and press the button again, the <code>WebViewOnlyActivity</code> appears immediately. <strong>Apparently Android cached something of WebView</strong>.</p>
  
  <p>Here are my testing devices:<br>
  1. Android 7.1.1: Slow<br>
  2. Android 7.0.0: Slow<br>
  3. Android 5.0.2 Slow<br>
  4. Android 4.4.1 Fast</p>
  
  <p>So it appears to me this only happens since Lollipop.</p>
  
  <p>However, such 1.x second delay is still unacceptable to me. Does anyone knows how to solve it? (Well, I think it is hard because I did nothing to this WebView... May be I should use some 3rd party WebView?)</p>
  
  <p>P.S. I have also used traceview to see what are the differences between a 7.1.1 device and 4.4.1 Device. It is clear that <code>WebView's</code> <code>init()</code> method is taking up a lot of time.</p>
  
  <p>7.1.1:
  <a href="https://i.stack.imgur.com/Ai4Mw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ai4Mw.png" alt="7.1.1 Trace View"></a>
  And further deeper:
  <a href="https://i.stack.imgur.com/1xdLA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/1xdLA.png" alt="7.1.1 Deeper"></a></p>
  
  <p>4.4.1:
  <a href="https://i.stack.imgur.com/Wz0r7.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Wz0r7.png" alt="4.4.1 Trace View"></a>
  And further deeper:
  <a href="https://i.stack.imgur.com/emCMz.png" rel="noreferrer"><img src="https://i.stack.imgur.com/emCMz.png" alt="4.4.1 Deeper"></a></p>
  
  <p>Big Difference!</p>
  
  <hr>
  
  <p>Although it is really empty, but requested by Axel, I will post the code for WebViewOnlyActivity as well:</p>
  
  <pre><code>public class WebViewOnlyActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_web_view_only);
  
      }
  }
  </code></pre>
  
  <hr>