Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design pattern for extending Android's activities?

While programming on Android, I end up writing a parent activity which is extended by several others. A bit like ListActivity. My parent activity extends Activity. if I intend to use a Map or a List, I can't use my parent activity as superclass - the child activity can only extend one activity obviously. As such I end up writing my parent activities with the same logic for Activity, ListActivity, MapActivity and so forth.

What am I looking for is some sort of trait functionality/design pattern which would help in this case. Any suggestions?

like image 939
charroch Avatar asked Apr 28 '10 21:04

charroch


2 Answers

I really dislike ListActivity, MapActivity etc. Basically they are activities which simply add a single view element at the cost of some flexibility. By adding a MapView or ListView to your XML appropriately, you end up with the same thing which can extend an Activity derived superclass directly. So just don't use any of those SomethingActivity classes for the most part.

like image 88
jqpubliq Avatar answered Sep 25 '22 15:09

jqpubliq


I've ended up having a base MyAbstractActivity extends Activity that incorporates shared logic and a MyAbstractListActivity extends MyAbstractActivity that mimics ListActivity (inflates layout.R.id.list, layout.R.id.empty, etc.; not much going on there).

like image 35
yanchenko Avatar answered Sep 22 '22 15:09

yanchenko