0

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.

Matt
  • 3,882
  • 14
  • 46
  • 89
  • Why would you have to copy entire class? Why can't you just extend the class? – Zielony Mar 13 '13 at 16:59
  • That is what I was trying to say, I am trying to avoid copying an entire class. I did this: I extended the android library class ````Quiz```` by doing this: ````public class ProQuiz extends Quiz````. Now I have a another class in my library which is named ````Categories````. The first line in this class is this: ````Quiz quiz = new Quiz();```` but I want to instantiate ````ProQuiz```` instead if they are running the Pro version of the app. That one line is what I want to override. – Matt Mar 13 '13 at 17:30

2 Answers2

2

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.

Abubakkar
  • 15,488
  • 8
  • 55
  • 83
  • I am pretty sure this is what I did. My question is how do I override that ````onCreate()```` method. – Matt Mar 13 '13 at 17:25
0

You can create a master Activity, from whom all other Activities derive (instead of the standard Activity.

Then you've the opportunity to add all the code within your onCreate() method you like to. To do all this, you should create a seperate project containing all your helper classes and files, which you then include in both projects.

Community
  • 1
  • 1
poitroae
  • 21,129
  • 10
  • 63
  • 81