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);
}
在该activity
的OnCreate()
中调用:startPreloadService()
;
在该activity
的OnDestroy()
中调用:stopPreloadService()
;
4.总结
开启制定进程的服务即实现预加载进程
网友评论