How to downgrade my Android app from 2.2 to 1.5 sdk without problems

I have an Android application that I started writing on sdk 2.2, but my Android phone has an Android version of version 1.5. I should easily convert my application to 1.5. I'm not quite sure, but I have not used too many 2.2-specific functions. Can you tell me how to do this?

+1
source share
3 answers

If you use Eclipse, change the minSdkVersion and targetSdkVersion and set 1.5 for the project, and everything that is not present in this version of the API will turn into an error.

+1
source

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; } // Private constructor prevents instantiation from other classes protected StaticAct() {} } 

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.

  /* * API Level 3 */ 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() { //unavilable in cupcake, do nothing } 

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.

+1
source

In manifest.xml:

 <uses-sdk android:minSdkVersion="integer" android:targetSdkVersion="integer" android:maxSdkVersion="integer" /> 

See here for more details.

The API level is inserted into the minSdkVersion, targetSdkVersion and maxSdkVersion fields (not that maxSdkVersion is deprecated in the toolbox, but will work in the store). For synopsis:

 Platform API Level Android 2.3 9 Android 2.2 8 Android 2.1 7 Android 2.0.1 6 Android 2.0 5 Android 1.6 4 Android 1.5 3 Android 1.1 2 Android 1.0 1 
0
source

Source: https://habr.com/ru/post/1337903/


All Articles