android's Activity extender

350 views Asked by At
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

1

There are 1 answers

0
jakebasile On BEST ANSWER

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 like ActivityExtensions, which you just call in to from the various onCreate methods and so on.