Search code examples
javaandroidoverridingandroid-librarymultiple-apk

Overriding just the onCreate() method of a class in Android library


I have 3 projects:

  1. Android library
  2. Lite version of app
  3. Pro version of app

I want to override just the onCreate() method of a class in the Android library. Is there a way to do this? I have been able to successfully override a whole class but I know it would save even more code duplication if I was able to override a single method in a class rather than override the whole class and duplicate 99% of the code just to change a couple of lines.

Hopefully that makes sense but let me know if it did not.


Solution

  • You can create a Super class of your Android library.

    Then create two classes for your Lite App and Pro App extending the above created class of your Android library.

    Then in those two subclasses override the onCreate method.