Using multiple inheritence of activity

ⅰ亾dé卋堺 提交于 2019-12-11 10:57:04

问题


Is there way to inherit two different activities in android. I have to display the Map on my activity which inherit from some other activity. i want to display a map on that activity but i can't display the map without inheriting MapActivity. Is there any other way to display the map without using MapActivity.


回答1:


No, android is java based. And java do not support multiple inheritance. Java supports multiple interfaces.

Maybe using fragments will help. Fragments could simulate multiple activities. However, all "activities" must be available as fragment. I am not sure whether there exist one for maps




回答2:


java does not support Multiple Inheritance, although you can come up with a clever design that will let you use functionality of multiple objects in your Activity.

read following article

http://csis.pace.edu/~bergin/patterns/multipleinheritance.html




回答3:


I modified the pattern listed by Mayank to assume that one base Activity doesn't change. I also made some tweak to show how arguments would work, considering activities will need access to base activity. In the following link, assume map activity would be BaseActivityAlpha. Here is my posting: http://www.anotherandroidblog.com/2013/01/03/extending-from-two-activities



来源:https://stackoverflow.com/questions/9921331/using-multiple-inheritence-of-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!