Essentially follow the Jean link at the top of the dev blog and take these recommendations. You are going to create a singleton class that lazy loads the desired class for the corresponding API level of the device on which it runs. Functions not available in the version should handle this use case.
public abstract class StaticAct { protected static StaticAct INSTANCE = null; public static StaticAct getInstance() { final int sdkVersion = Integer.parseInt(Build.VERSION.SDK); if(INSTANCE==null) if(sdkVersion < Build.VERSION_CODES.DONUT){ INSTANCE = new CupcakeStaticAct(); }else if (sdkVersion < Build.VERSION_CODES.ECLAIR){ INSTANCE = new DonutStaticAct(); }else if(sdkVersion < Build.VERSION_CODES.FROYO){ INSTANCE = new EclairStaticAct(); }else if(sdkVersion < Build.VERSION_CODES.GINGERBREAD){ INSTANCE = new FroyoStaticAct(); }else{ INSTANCE = new GingerbreadStaticAct(); } return INSTANCE; }
This abstract class will have some abstract methods that it defines as
public abstract boolean enableStrictMode();
A class can be defined for each api level. EDIT: these are all private classes defined inside the StaticAct.java file. This allows lazy loading to work correctly and prevent instantiation from other classes.
private static class CupcakeStaticAct extends StaticAct
The base class (StaticAct extension) must implement all the methods defined in StaticAct. If this method is not available for this api level, then handle this case, throw an error or return false (or completely ignore).
@Override public void enableStrictMode() {
As your classes grow at the api level, they only need to implement methods that have changed from previous versions. Thus, multi-touch APIs became available in 2.0, strict mode in version 2.3, etc.
source share