我正在使用的应用在生产中崩溃,并且用户报告以下堆栈跟踪。问题是我自己不能复制它。

Caused by: toothpick.registries.NoFactoryFoundException:
  at toothpick.registries.FactoryRegistryLocator.getFactoryUsingRegistries (FactoryRegistryLocator.java:49)
  at toothpick.configuration.ReflectionOffConfiguration.getFactory (ReflectionOffConfiguration.java:11)
  at toothpick.configuration.Configuration.getFactory (Configuration.java:113)
  at toothpick.registries.FactoryRegistryLocator.getFactory (FactoryRegistryLocator.java:38)
  at toothpick.ScopeImpl.lookupProvider (ScopeImpl.java:329)
  at toothpick.ScopeImpl.getInstance (ScopeImpl.java:58)
  at toothpick.ScopeImpl.getInstance (ScopeImpl.java:49)
  at my.package.name.activity.MainActivity$$MemberInjector.inject (MainActivity$$MemberInjector.java:13)
  at my.package.name.activity.MainActivity$$MemberInjector.inject (MainActivity$$MemberInjector.java:10)
  at toothpick.InjectorImpl.inject (InjectorImpl.java:25)
  at toothpick.Toothpick.inject (Toothpick.java:149)
  at my.package.name.BaseActivity.injectInScopes (BaseActivity.java:17)
  at my.package.name.activity.MainActivity.onCreate (MainActivity.java:120)
  at android.app.Activity.performCreate (Activity.java:6876)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1135)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3206)


在不同时间针对不同用户的不同活动中,它崩溃了。缺少的工厂存在(至少对我而言),如下所示。

public final class MainActivity$$MemberInjector implements MemberInjector<MainActivity> {
  @Override
  public void inject(MainActivity target, Scope scope) {
    target.myLogger = scope.getInstance(MyLogger.class);
    ...
  }
}


失踪的工厂:

public final class MyLoggerImpl$$Factory implements Factory<MyLoggerImpl> {
  @Override
  public MyLoggerImpl createInstance(Scope scope) {
    scope = getTargetScope(scope);
    RestApi param1 = scope.getInstance(RestApi.class);
    Scope param2 = scope.getInstance(Scope.class);
    MyLoggerImpl myLoggerImpl = new MyLoggerImpl(param1, param2);
    return myLoggerImpl;
  }

  @Override
  public Scope getTargetScope(Scope scope) {
    return scope;
  }

  @Override
  public boolean hasScopeAnnotation() {
    return false;
  }

  @Override
  public boolean hasProvidesSingletonInScopeAnnotation() {
    return false;
  }
}


模块:

bind(MyLogger.class).to(MyLoggerImpl.class).singletonInScope();


使用Toothpick反射或无反射配置时,会发生这种情况。我为何会收到此例外情况的任何想法?

最佳答案

我想通了。我使用错误的方式使用Toothpick,并且当应用程序在后台运行了一段时间并且用户重新输入了应用程序时,没有重新创建我的范围。

自我提醒:当应用程序处于后台时,Android应用程序和活动可能会被Android杀死。确保该应用程序和Toothpick可以安全地从中恢复。使依赖项注入模型保持简单。

08-05 03:33