kyle
kyle

Reputation: 3

Which way does the Android minimum SDK work?

If I have set the minimum SDK version to 16 (Jelly Bean 4.1) and I have coded most of my project in such a way that is compatible with this API level, but I have a small method which requires SDK version 25, will this stop the entire app working on a device with the Jelly Bean platform? Or will it allow them to install it and only that specific part won't work?

Upvotes: 0

Views: 246

Answers (3)

vjsantojaca
vjsantojaca

Reputation: 325

You can use annotations to remove these problems in the method.

@TargetApi(25)

1.You need to create a abstract class with the abstract method that you are talking about.

    public abstract class YourClass {
        public abstract void doSomething();
    }

2.Two implementation. One for a legacy version and other for a new version, in the new version you put @TargetApi.

  • Legacy Version:

    public class YourClassLegacy extends YourClass {
        public void doSomething(){
            //Legacy method
        }
    }
    
  • Implementation 25 version:

    @TargetApi(25) 
    public class YourClassNew extends YourClass {
        public void doSomething(){
            //25 version method
        }
    }
    

3.In the method that you call a this method (doSomething()), you need implement this.

    public static void methodFoo(Context context) {
        if (android.os.Build.VERSION.SDK_INT >= 25) {
            //call to YourClassNew.doSomething();
        }else{ 
            //call to YourClassLegacy.doSomething();
        } 
     }

Upvotes: 2

phoenix
phoenix

Reputation: 496

You should provide an alternative for alder versions by using a check.

if(android.os.Build.VERSION.SDK_INT >= 25) {
    // use new method
} else {
    // use alternative method
}

Upvotes: 0

user7568042
user7568042

Reputation: 244

then you need to code yourself to version 25 and re-code the old practice to keep up with the trends. Gradle WILL and MAY have issues higher API don't support certain methods and most particularly libraries where people use in their own methods

Upvotes: 0

Related Questions