How to implement common activities that can be expanded by normal, List and Map Activities?

I want to display the same options menu for all my applications. I created a general operation that implements the menu, and all my further actions expand it.

Problem: when I need to extend other specific actions, such as ListActivity and MapActivity, I cannot figure out how to extend the general activity and add List or Map behavior to a new class. To solve this problem, I had to create three different common actions, each of which extends Activity, ListActivity and MapActivity.

I tried to create an abstract activity, but it does not work, I will need to extend two classes at the same time. I could try the interfaces, but since I cannot implement the methods, I would have to embed a menu implementation in all second level classes, right?

+3
source share
1 answer

You cannot do this. Java does not allow multiple inheritance.

When I need this behavior and , it depends on the Activity life cycle . I just replicate its two abstract classes:

  • AbstractActivity
  • AbstractMapActivity

You can also learn more about multiple inheritance:

+2
source

Source: https://habr.com/ru/post/1769349/


All Articles