Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application的onCreate中在子线程使用Router.lazyInit(),同时onCreate的主线程中使用了Router.getService,导致偶现路由跳转页面失败 #73

Open
jiangming8 opened this issue Nov 13, 2019 · 1 comment

Comments

@jiangming8
Copy link

jiangming8 commented Nov 13, 2019

如题,在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");
}

}

`

@jzj1993
Copy link
Collaborator

jzj1993 commented Mar 12, 2020

Router.lazyInit()和UriAnnotationHandler中的init都调用了LazyInitHelper,有用synchronized做线程同步处理。理论上来说如果lazyInit还没执行完,主线程会等待lazyInit执行结束再跳转,不会出现跳转失败的情况。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants