通过重载 setContentView、setListAdapter 等继承自定义活动

发布于 2024-11-30 21:22:40 字数 946 浏览 0 评论 0原文

亲爱的开发人员,

需要您有关架构设计的建议,特别是有关自定义活动的继承的建议。 就我而言,有必要创建一个音乐应用程序,其功能与原始应用程序完全相同,但具有不同的 UI 和行为。

请告诉我下面描述的方法是否正确。我非常感谢您就如何最大限度地利用已实施的活动的功能提供建议。

我想从原始音乐播放器的标准活动继承我的曲目浏览器、播放列表浏览器、媒体播放等活动。然后我需要替换布局并拦截并适当处理一些事件。

挑战 1: setContentView 已在原始活动的 onCreate 内设置布局。我需要在 onCreate 中调用 super.onCreate,然后再次调用 setContentView。我调查过,可以多次调用setContentView,但是每次都需要实例化所有 UI 元素。我认为它们可能是性能和兼容性问题。 我的建议1: 重载setContentView并检测是否传递了适当布局的实例。如果是的话,我们会夸大活动。

挑战2: 几乎所有成员在原始活动中都是私有的,但我需要更换适配器,并且可能是原始活动中加载的一些广播接收器。 我的建议2: 我可以再次重载 setListAdapter、registerReceivers 等并检查它们尝试加载的实例类型。如果实例不是我的类的实例,我会跳过加载它们,否则我会加载它。

我正在寻找一个大项目的根本概念,所以我想提前确定我的想法是否正确。 请指出我是否违反了 Android 应用程序设计的概念。

Dear Fellow Developers

Need your advice about the architecture design, specifically about the inheritance of custom activities.
In my case, there is a necessity to create a music application with the exactly same functionally like the original one but with a different UI and behavior.

Please, hit me whether the approach described below is right or not. I would appreciate your suggestions how to use maximally functionalities of already implemented activities.

I think to inherit my track browser, playlist browser, media playback and etc. activities from the standard ones of the original music player. Then I would need to replace the layout and intercept with appropriate handling some events.

Challenge 1:
setContentView sets already the layout inside onCreate of an original activity. I need to call super.onCreate in my onCreate and then call setContentView again. I’ve investigated that it’s possible to call setContentView several times but it’s necessary to instantiate all UI elements each time again. I think that they may be performance and compatibility problems.
My suggestion 1:
overload setContentView and detect if the instance of the appropriate layout is passed. In case it’s we inflate the activity.

Challenge 2:
almost all members are private in original activities but I would need to replace the adapter and may be some broadcast receivers loaded in the original activities.
My suggestion 2:
again I can overload setListAdapter, registerReceivers and etc. and check what kind of instances they try to load. If the instances are not ones of my classes I would skip loading them otherwise I would load it.

I’m searching a root conception of a big project so I would like to be sure if my thinking is right in advance.
Please, point whether I’m not violating conceptions of Android applications design.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文