views:

41

answers:

1

I want to display the same options menu on all of my application's activities. I created a generic Activity that implements the menu, and all my further activies extend it.

The problem: when I need to extend other specific activities, like ListActivity and MapActivity, I can't figure out how to extend the generic activity and add the List or Map behaviour to the new class. To deal with the issue I had to create three different generic activities, each extending Activity, ListActivity and MapActivity.

I've tried creating an abstract activity but it doesn't work, I would need to extend two classes at the same time. I could try interfaces but since I can't implement methods, I would have to paste the menu implementation all over the second-level classes, right?

+2  A: 

You can't do this. Java doesn't allow multiple inheritance.

When I need this kind of behavior and it depends on the Activity lifecycle I just replicate it two abstract classes:

  • AbstractActivity
  • AbstractMapActivity

You can also read more about multiple inheritance:

Macarse
The second link really helped me. I knew I couldn't do it with multiple inheritance, I was looking for the alternatives.
Solivagant