I have an Android application that uses a class that extends the Activity class, let’s call it MyActivity. In that class I have a handler that handles various things. Now the activity that extends MyActivity class should be able to expand these things, that is it must be able to handle other things than MyActivity.
Here’s an example of what I want:
This is my modified Activity class that has a handler:
class MyActivity extends Activity {
protected Hander myActivityHandler = new Handler()
{
@Override
public void handleMessage(Message msg) {
switch(msg.what)
{
case CASE_1:
// do stuff
break;
case CASE_2:
// do other stuff
break;
}
}
}
}
And here’s the class that extends that class and I want to add more cases to the handler:
class MySuperSpecialActivity extends MyActivity {
// add/override cases of inherited myActivityHandler handler
}
I don’t know if it’s even possible, there’s probably a better way to achieve this functionality, but that’s how I started my code and a MyActivity class was necessary as it’s used a lot.
You may consider to implement Handler.Callback in your Activity:
Inherit new Activity from this Activity and overwrite “handleMessage”: