腾讯X5内核的初次加载卡顿的问题

最近应用集成腾讯的X5内核,首次打开X5内核的Webview是会出现卡顿和黑屏的现象,需要预加载!

首先在Application中设置

HashMap map = new HashMap();
map.put(TbsCoreSettings.TBS_SETTINGS_USE_SPEEDY_CLASSLOADER, true);
QbSdk.initTbsSettings(map);
initX5();//启动预加载的服务
private void initX5() {
    Intent intent = new Intent(this, PreLoadX5Service.class);
    startService(intent);
}
package com.wanxiangsiwei.beisu.utils;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;

import com.tencent.smtt.sdk.QbSdk;
import com.wanxiangsiwei.beisu.MApplication;

/**
 * 作者:syd_123 on 2018/9/12 15:21
 * 

* csdn https://blog.csdn.net/dong19900415 */ public class PreLoadX5Service extends Service { @Nullable @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); initX5(); preinitX5WebCore(); } private void initX5() { QbSdk.initX5Environment(getApplicationContext(), cb); Log.e("haha","预加载中..."); } QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() { @Override public void onViewInitFinished(boolean arg0) { // TODO Auto-generated method stub Log.e("haha", " onViewInitFinished is " + arg0); } @Override public void onCoreInitFinished() { // TODO Auto-generated method stub Log.e("haha","预加载中...onCoreInitFinished"); } }; private void preinitX5WebCore() { if(!QbSdk.isTbsCoreInited()) { // preinit只需要调用一次,如果已经完成了初始化,那么就直接构造view Log.e("haha","预加载中...preinitX5WebCore"); QbSdk.preInit(getApplicationContext(), null);// 设置X5初始化完成的回调接口 } } }

还需要在Mainifest中设置

 

最终应用启动后几秒便可顺利加载!

你可能感兴趣的:(Android)