tags:

views:

22

answers:

1

Hi All!

This is what we can read in the Service reference page here:

If you need your application to run on platform versions prior to API level 5, you can use the following model to handle the older onStart(Intent, int) callback in that case. The handleCommand method is implemented by you as appropriate:
// This is the old onStart method that will be called on the pre-2.0
// platform.  On 2.0 or later we override onStartCommand() so this
// method will not be called.
@Override
public void onStart(Intent intent, int startId) {
    handleCommand(intent);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    handleCommand(intent);
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}

This works perfectly for my 2.1 AVD.

But how can I test this in my 1.5 AVD as it gives me logical compilation errors.

A: 

I just tested this out, it should run as described. You have to compile your project against an Android version higher than API level 5 in order to use the method onStartCommand(). Remember to select Android 2.0.1 (level 6) in the 'Android' tab of your project settings and set minSdkVersion to 3 in your Android manifest.

You should be able to run this compiled APK on both Android 1.5 and Android 2.1.

mreichelt
Thanks a lot for your answer. It works also for me with my emulator version 2.1. My real problem is how can I test that on my 1.5 emulator.
Plissken
If you did it the right way, you can just start it with a 1.5 AVD. Have you set your minSdkVersion to 3? Otherwise it won't work. If you then still have problems: Which errors do you get?
mreichelt
I've just found how to run my app on 1.5 AVD: As usually, I have selected the project build target "Android 2.1" needed to build successfully the app. And I've set the deployment target selection mode to manual. This way I can select my 1.5 AVD when I run the app. Previously it was set to automatic and the launcher refused to start the app on the 1.5 emulator as my AVD was not compatible with the project target 'Android 2.1'.
Plissken