Open jiangming8 opened 4 years ago
如题,在Application的onCreate方法中,在使用后台线程进行懒加载Router.lazyInit()。同时onCreate的主线程中使用了Router.getService,导致偶现路由跳转页面失败。调试后发现是路由表ServiceLoaderInit类的init方法还没有执行完成,就开始调用了UriAnnotationHandler的performInit方法。
请问这种情况应该怎么处理。
` public class MApplication extends Application {
public void onCreate() { DefaultRootUriHandler rootHandler = new DefaultRootUriHandler(context); Router.init(rootHandler); // 懒加载后台初始化(可选) new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { Router.lazyInit(); return null; } }.execute(); ... Router.getService(IHomeMineModule.class, "homemine"); }
}
`
Router.lazyInit()和UriAnnotationHandler中的init都调用了LazyInitHelper,有用synchronized做线程同步处理。理论上来说如果lazyInit还没执行完,主线程会等待lazyInit执行结束再跳转,不会出现跳转失败的情况。
如题,在Application的onCreate方法中,在使用后台线程进行懒加载Router.lazyInit()。同时onCreate的主线程中使用了Router.getService,导致偶现路由跳转页面失败。调试后发现是路由表ServiceLoaderInit类的init方法还没有执行完成,就开始调用了UriAnnotationHandler的performInit方法。
请问这种情况应该怎么处理。
` public class MApplication extends Application {
}
`