提交 2e4e9b4d 编写于 作者: J johnsonlee 提交者: zhiguoWang

Improves web view preloading

上级 d85074e0
......@@ -14,6 +14,10 @@ public final class Looper {
throw new RuntimeException("Stub!");
}
public static MessageQueue myQueue() {
throw new RuntimeException("Stub!");
}
public static void prepare() {
throw new RuntimeException("Stub!");
}
......
......@@ -3,6 +3,8 @@ package com.didiglobal.booster.instrument;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.MessageQueue;
import android.os.SystemClock;
import android.util.Log;
......@@ -18,17 +20,22 @@ import static com.didiglobal.booster.instrument.Reflection.invokeStaticMethod;
public class ShadowWebView {
public static void preloadWebView(final Application app) {
try {
app.getMainLooper().getQueue().addIdleHandler(new MessageQueue.IdleHandler() {
@Override
public boolean queueIdle() {
startChromiumEngine(app);
return false;
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
try {
Looper.myQueue().addIdleHandler(new MessageQueue.IdleHandler() {
@Override
public boolean queueIdle() {
startChromiumEngine(app);
return false;
}
});
} catch (final Throwable t) {
Log.e(TAG, "Oops!", t);
}
});
} catch (final Throwable t) {
Log.e(TAG, "Oops!", t);
}
}
});
}
private static void startChromiumEngine(final Context context) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册