Dianne, what's wrong with checking version number?

Unless there's some problem with it I'd suggest going with Mark's solution
(also covered in
http://devtcg.blogspot.com/2009/12/gracefully-supporting-multiple-android.html).
You can use it for most cases and it's much cleaner (and definitely stay
away from reflection-based one unless, for some reason, there's no other
choice).

Cheers,
Max


On 21 April 2010 01:43, Dianne Hackborn <hack...@android.com> wrote:

>
> http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html
>
> Or actually it appears this has become a tech article:
>
> http://developer.android.com/resources/articles/backward-compatibility.html
>
>
> <http://developer.android.com/resources/articles/backward-compatibility.html>The
> last section, "Using a wrapper class," talks about this.
>
> On Tue, Apr 20, 2010 at 5:01 PM, Christopher <
> christopher.t.mor...@gmail.com> wrote:
>
>> Diane,
>>
>> Can you please explain what blog post you're referring to in your
>> post?
>>
>> On Apr 20, 2:26 pm, Dianne Hackborn <hack...@android.com> wrote:
>> > I suggest not using the SDK version, but just use the trick in the blog
>> post
>> > to detect if the class doesn't exist before trying to use it.
>> >
>> >
>> >
>> >
>> >
>> > On Tue, Apr 20, 2010 at 1:00 PM, kec6227 <kec6...@gmail.com> wrote:
>> > > Oh ok, that makes perfect sense. Thank you.
>> >
>> > > On Apr 20, 12:11 pm, Mark Murphy <mmur...@commonsware.com> wrote:
>> > > > kec6227 wrote:
>> > > > > Using? a wrapper class of sorts? If I initiate the
>> WallpaperManager
>> > > > > anywhere in my code, it will throw a VerifyError on older
>> platforms, I
>> > > > > tried something like this:
>> >
>> > > > > if(Integer.parseInt(Build.VERSION.SDK) >= 5){
>> > > > >     WallpaperManager wallMan..
>> > > > > ...blah blah
>> > > > > }
>> >
>> > > > > The only way it does not throw a verifyerror is when I don't use
>> the
>> > > > > WallpaperManager anywhere.
>> >
>> > > > That's not strictly true. You only will get a VerifyError if you
>> load a
>> > > > class that refers to WallpaperManager.
>> >
>> > > > So, the trick is to use reflection or conditional class loading to
>> only
>> > > > load your code referencing WallpaperManager on suitable versions.
>> >
>> > > > For example:
>> >
>> > > > if(Integer.parseInt(Build.VERSION.SDK) >= 5){
>> > > >         new MyWallpaperBridge().goDoSomething();
>> >
>> > > > }
>> >
>> > > > Or, create an interface and two implementations, and choose the
>> > > > implementation based on the version, as seen here:
>> >
>> > > >
>> http://github.com/commonsguy/cw-advandroid/tree/master/Contacts/Spinn...
>> >
>> > > > --
>> > > > Mark Murphy (a Commons Guy)http://commonsware.com|
>> > >http://twitter.com/commonsguy
>> >
>> > > > Android Training in US: 14-18 June 2010:http://bignerdranch.com
>> >
>> > > > --
>> > > > You received this message because you are subscribed to the Google
>> > > > Groups "Android Developers" group.
>> > > > To post to this group, send email to
>> android-developers@googlegroups.com
>> > > > To unsubscribe from this group, send email to
>> > > > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com><android-developers%2Bunsubs
>> cr...@googlegroups.com>
>> > > > For more options, visit this group athttp://
>> > > groups.google.com/group/android-developers?hl=en
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> > > Groups "Android Developers" group.
>> > > To post to this group, send email to
>> android-developers@googlegroups.com
>> > > To unsubscribe from this group, send email to
>> > > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com><android-developers%2Bunsubs
>> cr...@googlegroups.com>
>> > > For more options, visit this group at
>> > >http://groups.google.com/group/android-developers?hl=en
>> >
>> > --
>> > Dianne Hackborn
>> > Android framework engineer
>> > hack...@android.com
>> >
>> > 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
>> android-developers@googlegroups.com
>> > To unsubscribe from this group, send email to
>> > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
>> > For more options, visit this group athttp://
>> groups.google.com/group/android-developers?hl=en
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>
>
> --
> Dianne Hackborn
> Android framework engineer
> hack...@android.com
>
>
> 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 android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to