You absolutely can.  In fact Java gives you a lot of neat things you can do.
 For example, if you want to write a Service that uses the new
onStartCommand() on 2.0 but still works on older versions with the old
onStart(), just write it like this:

    @Override
    void onStart(Intent intent, int startId) {
        handleCommand(intent);
    }

    @Override
    void onStartCommand(Intent  intent, int flags, int startId) {
        // Consume command, so old onStart() is not called.
        handleCommand(intent);
    }

    // Handle start from either old or new method.
    void handleCommand(Intent intent) {
        // ...
    }

This article covers a lot more of what you can do:

http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html

Note that reflection is useful for simple things, but for more extensive use
of APIs you can follow the wrapper class approach which works very well.
 You can basically have large sections of you app using newer APIs, and as
long as you don't try to run those classes you will be fine.  (So in fact
another approach you could take is to just look at the API version and use
one class code vs. another based on it.)

On Wed, Nov 25, 2009 at 8:16 PM, Ravi <[email protected]> wrote:

> My understanding is that You can't. I cloned my app for 2.0 (ofcourse
> you will loose your feedback and popularity) and set minSDK to 5
>
> Catch 22: If you set min sdk to 5 aka 2.0, 1.5 & 1.6 can not see the
> app. If you set to 1.5 or 1.6 then you can not see your cdma package.
>
>
> On Nov 25, 9:31 pm, Bryan <[email protected]> wrote:
> > Sorry for the simple question, but I'm having trouble finding an
> > answer. My app targets 1.5, and runs fine on my phone (1.6), but to
> > support droid, I need the package android.telephony.cdma from 2.0.
> > Targeting 2.0 excludes the current devices running my app (including
> > my own G1), but as it is now, I can't support the Droid. Thanks!
>
> --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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