gpt4 book ai didi

android的 Activity 扩展器

转载 作者:行者123 更新时间:2023-11-29 22:28:21 25 4
gpt4 key购买 nike

android.app.Activty
|
|
|
|
com.mycompany.ActivityWrapper
| <--------------------------------\
| \ |
| | |
| | |
| android.app.ListActivty android.app.ExpandableListActivity
| | |
| | |
| | |
MyActivity1 | |
| |
MyActivity2 MyActivity3

我需要制作类 (com.mycompany.ActivityWrapper) 来扩展 android.app.Activity 和扩展以下方法:

  • 创建时
  • onResume
  • onConfigurationChanged
  • 打开菜单

我想要我所有的 Activity (已经扩展到 monent android.app.Activity,android.app.?ListActivity)使用我的 com.mycompany.ActivityWrapper 的代码

我不知道如何实现这个(可能通过反射 %))。

请帮帮我

最佳答案

我有一些相同的问题,尽管这样做让我很痛苦,但唯一有用的方法是创建多个基类。例如,您将有一个 ActivityWrapper , ListActivityWrapper , ExpandableListActivityWrapper .您可以通过将要调用的公共(public)代码移动到一个新类中来避免一些代码重复,例如 ActivityExtensions ,您只需从各种 onCreate 调用它方法等。

关于android的 Activity 扩展器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5169082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com