On Tue, Jan 18, 2011 at 5:51 PM, Hari Edo <[email protected]> wrote:

> Since my general-purpose class may be used by some other projects that do
> not need Analytics, I thought I'd make these methods detect the JAR file at
> runtime, rather than require the JAR in every project.
>
> So I use the Java "reflection" mechanisms to detect if the JAR
> is available, and if so, to indirectly invoke the methods instead.  If the
> JAR is not present, then I decided that calling these methods should just do
> nothing.
>

Alternate suggestion: create an "Analytics" interface with two concrete
implementations: one that actually uses GoogleAnalytics (basically what you
have now) and a "dummy" that does nothing. In the project you need GA, you
instantiate the GA implementation. In the one you don't, you instantiate the
dummy.

No crazy reflection necessary and, bonus, if you decide to try alternate
analytics libraries (say, Flurry), you have an interface to code to and just
have to add a concrete implementation for it - nothing else has to change
(much).

-------------------------------------------------------------------------------------------------
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

Reply via email to