美文网首页
android 预加载进程

android 预加载进程

作者: 路Promenade | 来源:发表于2019-04-22 23:15 被阅读0次

1.前言

WebView独立进程时,打开webView所在的Activity,会出现白屏或黑屏

也就是说从一个进程activity跳转另一个进程的activity,会出现白屏或黑屏

2.思路

在跳转之前,预加载进程,从而避免启动进程的时间

选择看不见的组件进行预加载,如Service、广播

3.实现

1 创建预加载服务类

public class PreloadService extends Service {

    @Override   
    public IBinder onBind(Intent intent) {     
        return null;   
    }

}

2 清单文件中注册并制定 android:process 要预加载的进程

<service
    android:name="com.lugq.preloaddemo.PreloadService"
    android:process=":remote"/>

3 跳转 activity 之前预加载进程

private void startPreloadService() {
    Intent intent = new Intent(this, PreloadService.class);
    this.startService(intent);
}

private void stopPreloadService(){
    Intent intent = new Intent(this, PreloadService.class);
    this.stopService(intent);
}

在该activityOnCreate()中调用:startPreloadService();
在该activityOnDestroy()中调用:stopPreloadService();

4.总结

开启制定进程的服务即实现预加载进程

相关文章

网友评论

      本文标题:android 预加载进程

      本文链接:https://www.haomeiwen.com/subject/gzvpgqtx.html