Short answer is you don't.

Long answer is you implement something like a "facade" pattern
combined with a "factory" pattern.

The classes that you want to load which have API 7 specific code will
only be loaded by the classloader when they are referenced at
runtime.  Hence pre-api 7 installs will only barf if you try to
instantiate, or reference one of your new classes.  You can happily
package the newer classes in your APK as long as they are not
referenced.

So.. one way to do this would be:

1. Implement 2 versions of the PhoneStateListener, one for API 7 and
one for pre-API 7
2. Create a PhoneStateListenerFactory which has a single method called
getListener() ( or whatever )
3. In the PhoneStateListenerFactory#getListener() you have the logic
which determines which platform is running, and instantiates the
relevant listener.

For Example (pseudo code):

public ... PhoneStateListener getListener() throws ... {

PhoneStateListener listener = null;
String className = null;
if(API7) {
        className = "com.blah.API7PhoneStateListener";
}
else {
        className = "com.blah.LegacyPhoneStateListener";
}

listener = ( PhoneStateListener )
Class.forName(className).newInstance();

return listener;

}

This way the actual implementation of API7PhoneStateListener will
never see the light of day on pre-API7 devices.



On Sep 22, 10:06 pm, Pent <[email protected]> wrote:
> Since API 7, PhoneStateListener has a function:
>
> void onSignalStrengthsChanged( SignalStrength signalStrength )
>
> Question: how can I override this via reflection so that I can stay
> backwards
> compatible with earlier APIs that don't have the SignalStrength
> class ?
>
> If I make the argument an Object, the signature changes of course.
>
> TIA,
>
> Pent

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