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

Dagger-Hilt 2.49: Activity onCreate() and onDestroy() code is generated, but our base Activity class has these final #4202

Open
caltseng opened this issue Jan 2, 2024 · 3 comments

Comments

@caltseng
Copy link

caltseng commented Jan 2, 2024

Upgrading Hilt version from 1.0.0 to 1.1.0 (dagger hilt android from 2.45 to 2.50). We have a custom Activity that we inherit from that is final, but Hilt generates code that overrides these methods and compiling doesn't work.

Edit - looks like this was added in 2.49, PR

Error message:

error: onDestroy() in Hilt_MainActivity cannot override onDestroy() in AppCompatCuustomActivity public final void onDestroy() { ^ overridden method is final 2 errors
Generated Code:

  @CallSuper
  @Override
  public final void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initSavedStateHandleHolder();
  }

  @Override
  public final void onDestroy() {
    super.onDestroy();
    if (savedStateHandleHolder != null) {
      savedStateHandleHolder.clear();
    }
  }
@caltseng caltseng changed the title Hilt 1.1.0: Activity onCreate() and onDestroy() code is generated, but our base Activity class has these final Dagger-Hilt 2.49: Activity onCreate() and onDestroy() code is generated, but our base Activity class has these final Jan 2, 2024
@wanyingd1996
Copy link

Hi, Caleb, we had to override the lifecycle methods in order to lazily provide SavedStateHandle, I'll try to improve the error message, do you have to use final for those methods?

@caltseng
Copy link
Author

Let me follow up to see if we can get our own custom activity to remove final. I have a suspicion those were added a long time ago and is now obsolete. It's honestly also a bit of an antipattern anyways.

@caltseng
Copy link
Author

caltseng commented Jan 18, 2024

@wanyingd1996 - We removed final from our base Activity classes. Can probably close this out. (That said, still wondering if there's another pattern of implementation that could avoid this, but probably another conversation to be had if this is a more common issue)

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