2

I'm working on a project that was originally designed for Honeycomb; we want to make it compatible with 2.3.3. I'm doing this by converting a copy of the original project to a library project, including this library into several new projects, and subclassing some elements in the new projects to use specific APIs.

However we have lots of AsyncTask<...> subclasses; AsyncTask<...> exists in 2.3.3 but the onCancelled() method, which we implement, only exists since Honeycomb. I'm concerned that if I leave these classes in the central library project, the onCancelled() method will not be hit because (effectively) it has been built against the 2.3.3 Android library, which doesn't have it. However, I don't want to reproduce these classes in every sub-project without a good reason and I can't see how subclassing would make anything better: the superclass would STILL be against the 2.3.3 version of AsyncTask<...>. My question is: does Java/Android allow for this, and will onCancelled() be hit in higher versions of Android?

animuson
  • 53,861
  • 28
  • 137
  • 147
Andrew Wyld
  • 7,133
  • 7
  • 54
  • 96
  • 1
    you do something in onCancelled() method in Honeycomb? What will you do in 2.3.3 instead of onCancelled()? – Murat Mar 05 '12 at 19:07
  • Wait for the `AsyncTask` to complete and discard the results; in this case we call `requestCancelDecode()` on a `BitmapRegionDecoder`, which saves a bit of memory and processing and is worth doing. – Andrew Wyld Mar 06 '12 at 10:25
  • PS `BitmapRegionDecoder` obviously doesn't exist pre-2.3.3 but we may want our app to run on Kindle fire devices, hence the need to extend back to 2.3.3. – Andrew Wyld Mar 06 '12 at 10:35
  • Alternatively you can create your own asynctask implementation to support newly added functions down to API level 3, checkout my answer [here](http://stackoverflow.com/questions/7211684/asynctask-executeonexecutor-before-api-level-11). – yorkw Mar 07 '12 at 00:25

1 Answers1

0

You can relase multiple APKs. One for the honeycomb and later API level , one for the previos API levels.Otherwise you should use Compatibility package but this package doesnt support all APIs. For multiple APKs support: http://developer.android.com/guide/market/publishing/multiple-apks.html

Murat
  • 3,084
  • 37
  • 55
  • This is in fact what we are planning to do (actually we are creating a central library project, subsidiary library projects for all Android versions with significant changes, then application projects containing the secondary libraries) but I don't want to re-implement all the `AsyncTask` subclasses in each sub-library, particularly as this means I have to make a lot of things abstract, unless I have to! Thanks, though :) – Andrew Wyld Mar 07 '12 at 13:19