Extending Activity and List Activity

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Extending Activity and List Activity

Postby akhalsa » Sat Mar 12, 2011 3:27 am

Hi Guys

I have a quick question about extending an Activity. Basically, all my activities are doing a few things in common, which I addressed in what I thought was a clever way by putting all the code into a single class which extends Activity. Unfortunately, it turned out that a couple of these activities actually need to be ListActivities.

I would prefer not to make a new intermediate class that extends ListActivity but otherwise is identical to the class that extends activity. I considered using an interface which would take care of most of the issue, but unfortunately, I need to have some of the fields as protected which I can't do with an interface. Does anyone have any suggestions?
akhalsa
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Mar 12, 2011 3:17 am

Top

Re: Extending Activity and List Activity

Postby MichaelEGR » Sat Mar 12, 2011 5:25 am

As things go I am releasing a middleware platform called TyphonRT for Android soon that definitely addresses your design concern.

Indeed this is a good example of how a component oriented architecture like TyphonRT shines. Essentially there is a "lifecycle component" and this class mirrors all the Activity methods. The base TyphonActivity manages lifecycle components and delegates calling the appropriate methods when invoked by an Activity via iteration. For ListActivity and any other specialized base Activity in the Android API there are likewise extended lifecycle components with the additional ListActivity or specialized methods defined by the given Activity.

What you can do to solve your problem with TyphonRT is create a custom lifecycle component extending the base type and add any custom logic you need to handle for the Activitiy methods. You can also add your protected methods and any other methods in your custom lifecycle component. You can then create a new TyphonActivity (Activity w/ component management & essential iteration) or a TyphonListActivity (ListActivity w/ component management & iteration) and simply slot in one or more custom components into either.

Even better is that there is an additional XML configuration file for TyphonRT to be able to declaratively specificy components to load and you can filter based on Android OS version, device family/name, screen size, and many other parameters thus being able to provide differentiation across the Android ecosystem without having to embed conditional logic in the codebase itself.

I've been working hard on TyphonRT for quite some time, but a semi-public release is coming soon with a likely full public launch by end of Q2. Drop me an email at the contact address http://www.typhonrt.org/ and I'll let you know when the semi-public release is available.

The essential pattern I described above though is a good way to solve your design problem though.
Founder & Principal Architect; EGR Software LLC
http://www.typhonrt.org
http://www.egrsoftware.com
User avatar
MichaelEGR
Senior Developer
Senior Developer
 
Posts: 147
Joined: Thu Jan 21, 2010 5:30 am
Location: San Francisco, CA

Top

Return to General

Who is online

Users browsing this forum: No registered users and 3 guests