lightcycle: Templated base class : Cannot find symbol class ActivityType in LightCycleBinder

Hello,

I’m trying to reproduce the same behavior as LightCycleAppCompatActivity in a BaseActivity, so I implemented LightCycleDispatcher<ActivityLightCycle<T>> in my base class and dispatch event in each lifecycle callback.

My base class prototype :

public abstract class BaseActivity<ActivityType extends BaseActivity> extends AppCompatActivity
    implements LightCycleDispatcher<ActivityLightCycle<ActivityType>>

which is the same as LightCycleAppCompatActivity :

public abstract class LightCycleAppCompatActivity<ActivityType extends LightCycleAppCompatActivity>
        extends AppCompatActivity
        implements LightCycleDispatcher<ActivityLightCycle<ActivityType>> 

The issue is when I use my base class LightCycleBinder cannot resolve the type of my child activity and generate this code below :

public final class MainActivity$LightCycleBinder {
  public static void bind(MainActivity target) {
    final com.soundcloud.lightcycle.ActivityLightCycle<ActivityType> mPresenter$Lifted = com.soundcloud.lightcycle.LightCycles.lift(target.mPresenter);
    target.bind(mPresenter$Lifted);
  }
}

But when my MainActivity extends directly LightCycleAppCompatActivity the type is revolved :

public final class MainActivity$LightCycleBinder {
  public static void bind(MainActivity target) {
    final com.soundcloud.lightcycle.ActivityLightCycle<MainActivity> mPresenter$Lifted = com.soundcloud.lightcycle.LightCycles.lift(target.mPresenter);
    target.bind(mPresenter$Lifted);
  }
}

I tried to create another base class with exactly the same code contain in LightCycleAppCompatActivity but it still doesn’t work, it’s seems to work only with LightCycleAppCompatActivity.

It’s there any way to make it work using my BaseActivity class

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@glung Oh sure, I think we should bring it back in, but until now it was pretty coupled to the processor & the binding, so I’ve removed it during the work I was doing and maybe we can come up with an abstraction around it. I’ll create the PR in the next week or so when I’ve got somewhere, and let’s chat from there 👍

Hello @MehdiChouag, I just took a look.

You spotted a weakness, we should at least update the documentation. Long story short, you should set the type explicitly, i.e. make your SearchActivity implements LightCycleDispatcher<ActivityLightCycle<SearchActivity>>.

Note : You could also make your BaseActivity implements LightCycleDispatcher<ActivityLightCycle<BaseActivity>> but then the SearchPresenter won’t accept SearchActibity.

This is because of the Processor not beeing able to determine the dispatched type because it did not recognize your BaseActivity. As of now, it only recognizes the following https://github.com/soundcloud/lightcycle/blob/e3844cc90de9302de2146a6c1d0a35a8fbadae37/lightcycle-processor/src/main/java/com/soundcloud/lightcycle/LightCycleDispatcherKind.java#L5-L5