On Fri, Aug 20, 2010 at 3:58 PM, Moto <[email protected]> wrote:
> Mmm Activity proxy class? I kind of understand the concept but I'm
> not following well... you have a simple example?
>
class ActivityProxy
{
mActivity = null;
public ActivityProxy(Activity activity)
{
mActivity = activity;
}
// Do whatever every Activity should do in onCreate
public void onCreate()
{
if (Prefs.runFullScreen)
mActivity->setFullScreen();
}
}
public MyActivity1 : Activity
{
ActivityProxy proxy = new ActivityProxy(this);
protected void onCreate()
{
proxy->onCreate(); // Now all common code is abstracted here.
...
}
}
public MyActivity2 : Activity
{
ActivityProxy proxy = new ActivityProxy(this);
protected void onCreate()
{
proxy->onCreate(); // Now all common code is abstracted here.
...
}
}
So your proxy does all the work that you want other Activities the ability
to do, but it's centralized and encapsulated. The tradeoff, of course, being
you need an instance in each Activity. But this is really no different than
the alternative of overriding a base and then overriding all the required
methods.
This may not be worth it in your simple case, but once your app grows and
you have tons of common code you can't put in a base class, it proves its
worth.
-------------------------------------------------------------------------------------------------
TreKing <http://sites.google.com/site/rezmobileapps/treking> - Chicago
transit tracking app for Android-powered devices
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en