Multiple activities have identical onCreateOptionsMenu, onOptionsItemSelected and onKeyDown. When I implement a change, I have to do it in every activity (work time * activity count). Is there a way to reuse the code (for example write all of the three methods in one place and put down a reference to it in every activity)?
Multiple activities have identical onCreateOptionsMenu, onOptionsItemSelected and onKeyDown. When I implement a change, I
Share
Sure, just create your own
Activityclass that all your classes inherit from.A bit like this – create an abstract base class that inherits from
Activityand implements common behaviour:Then make your individual activities inherit from your base class: