Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I create a single class which can be the parent for every type of Activity?
    text
    copied!<p>I wish to have a single class which all of my <code>Activity</code> classes extend. I have <code>ListActivities</code>, <code>Activities</code>, <code>MapActivities</code>, <code>TabActivities</code>, etc in my App.</p> <p>I have many of these different activities in my app, ~12 activities. I want each of them to have the methods which are in the parent class.</p> <p>Right now, i have created 4 parent activity classes which are extended from a certain activity depending on their type(<code>ListActivity</code>, <code>Activity</code>, <code>MapActivity</code>, <code>TabActivity</code>)</p> <p>I am creating a lot of redundant code - each of the 4 parent activities has almost identical code, in exception for what class activity it extends.</p> <p>Here is an example that may clarify what my problem is:</p> <ul> <li>I have an <code>Activity</code>: <code>MenuScreen</code> which extends <code>BaseListActivity</code> </li> <li><code>BaseListActivity</code> extends <code>ListActivity</code></li> <li><p><code>BaseListActivity</code> contains methods and fields which i want all my activities to have access to</p></li> <li><p>I have another <code>Activity</code>: <code>HomeScreen</code> which extends <code>BaseActivity</code></p></li> <li><code>BaseActivity</code> extends <code>Activity</code></li> <li><code>BaseActivity</code> contains the same methods and fields which are in my other <code>Base[&lt;type&gt;]Activity</code> classes(such as <code>BaseListActivity</code>)</li> </ul> <p>these methods/fields are copy-pasted to all my <code>Base[&lt;type&gt;]Activity</code>, and seems awfully redundant to me.</p> <p>Can i create a master activity class which all types of Activity classes can use as its parent? if not, am i stuck with copy and pasting this code and feeling gross/dirty about it?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload