[android-developers] startForeground Backwards compatability

2009-11-15 Thread G
Hi, I've got a question as I don't have an Android 2.0 device to test
on and this particular aspect seems untestable in the emulator.

I've got a service that needs to be run as a foreground service. I
have a notification that stops it etc, so I have no problem using
startForeground instead of setForeground. However, I'd like to have 1
version of my app that works across all platforms... Is this possible?
If my app is compiled with Android 1.5 and uses setForeground, then
will that command actually work on an Android 2.0 device, or does it
not matter which sdk was used to compile? I've tried compiling with
2.0, and surrounding the call to startForeground with a try/catch, but
that throws a VerifyError when the service is started, when run on a
1.5/6 device since startForeground doesn't exist there. Can I catch
and ignore the VerifyError somehow and make it work that way?

Any help would be appreciated, I really don't want to have to make a
2nd branch of my app.

Regards,
Geoff

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


Re: [android-developers] startForeground Backwards compatability

2009-11-15 Thread TreKing
Yes, this is possible and definitely testable in the emulator. I actually
just update my own app to account for this change in 2.0.

I don't think you can get around the VerifyError but you can check if the
method you want to use exists. Build against 2.0 and use reflection to check
if the startForeground exists and use it if it does, otherwise default to
setForeground.

There was a blog post about using reflection for things like this though I
don't have the link handy.

Hope that helps.

-
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking


On Sun, Nov 15, 2009 at 2:27 PM, G ghack...@gmail.com wrote:

 Hi, I've got a question as I don't have an Android 2.0 device to test
 on and this particular aspect seems untestable in the emulator.

 I've got a service that needs to be run as a foreground service. I
 have a notification that stops it etc, so I have no problem using
 startForeground instead of setForeground. However, I'd like to have 1
 version of my app that works across all platforms... Is this possible?
 If my app is compiled with Android 1.5 and uses setForeground, then
 will that command actually work on an Android 2.0 device, or does it
 not matter which sdk was used to compile? I've tried compiling with
 2.0, and surrounding the call to startForeground with a try/catch, but
 that throws a VerifyError when the service is started, when run on a
 1.5/6 device since startForeground doesn't exist there. Can I catch
 and ignore the VerifyError somehow and make it work that way?

 Any help would be appreciated, I really don't want to have to make a
 2nd branch of my app.

 Regards,
 Geoff

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