减少使用 Activity 和 MapActivity 时的重复代码
我可以创建一个像 MyAppActivity 这样的中间活动类,以包含我的活动中使用的通用代码,但如果应用程序还需要子类化 MapActivity,这显然不起作用。
解决办法是什么?我看到的选项:
将尽可能多的方法移至 ActivityUtils 类 (yuk)
接受一些重复 (yuk)
子类 MapActivity,并使用该类来子类化我的实际活动。我不确定这有什么缺点。如果没有 MapView 存在,MapActivity 似乎不会反对。丑陋,但我怀疑比复制大量代码更丑陋,这对质量和维护有直接的负面影响。
此挑战也适用于 PreferenceActivity。
I can create an intermediate activity class like MyAppActivity, to contain common code used across my activities, but this obviously doesn't work if the app also needs to subclass MapActivity.
What's the solution? Options I see:
Move as many methods as possible to an ActivityUtils class (yuk)
Accept some duplication (yuk)
Subclass MapActivity, and use that class to subclass my actual activities. I'm not sure what the downside to this is. MapActivity doesn't seem to object if there's no MapView present. Ugly, but I suspect rather less ugly than duplicating lots of code which has a direct negative impact on quality and maintenance.
This challenge also applies with PreferenceActivity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不能使用带有静态方法的公共 Helper 类吗?
编辑:啊,也许这是您首先提到的选项
It is not possible to use a common Helper class with static methods?
EDIT: ah maybe that's your first mentioned option