android的Activity扩展器
android.app.Activty
|
|
|
|
com.mycompany.ActivityWrapper
| <--------------------------------\
| \ |
| | |
| | |
| android.app.ListActivty android.app.ExpandableListActivity
| | |
| | |
| | |
MyActivity1 | |
| |
MyActivity2 MyActivity3
我需要创建扩展 android.app.Activity 的类 (com.mycompany.ActivityWrapper) 和 扩展以下方法:
- onCreate
- onResume
- onConfigurationChanged
- onMenuOpened
我想要我的所有活动(已经在当前 android.app.Activity、android.app.?ListActivity 处扩展) 使用我的 com.mycompany.ActivityWrapper 的代码
我不知道如何实现这个(也许通过反射%))。
请帮助我,请
android.app.Activty
|
|
|
|
com.mycompany.ActivityWrapper
| <--------------------------------\
| \ |
| | |
| | |
| android.app.ListActivty android.app.ExpandableListActivity
| | |
| | |
| | |
MyActivity1 | |
| |
MyActivity2 MyActivity3
I need to make class (com.mycompany.ActivityWrapper) which extends android.app.Activity and
extends following methods:
- onCreate
- onResume
- onConfigurationChanged
- onMenuOpened
I want all my activities (which already extends at the monent android.app.Activity, android.app.?ListActivity)
use code of my com.mycompany.ActivityWrapper
I have no ideas how to implement this ( maybe via reflection %) ).
Help me, plz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一些相同的问题,尽管这样做让我很痛苦,但唯一有用的方法是创建多个基类。例如,您将有一个 ActivityWrapper、ListActivityWrapper、ExpandableListActivityWrapper。您可以通过将要调用的公共代码移动到一个新类(例如
ActivityExtensions
)中来避免一些代码重复,您只需从各种onCreate
中调用它即可。代码>方法等等。I have some of the same issues, and although it pained me to do so the only useful way of doing it is by creating multiple base classes. For example, you would have a
ActivityWrapper
,ListActivityWrapper
,ExpandableListActivityWrapper
. You can get around some of the code duplication by moving the common code you want to call off into a new class, something likeActivityExtensions
, which you just call in to from the variousonCreate
methods and so on.