Change method visibility based on android sdk

Suppose I have developed an android XYZ library that has animateWithTransition () methods , which has code associated with the transition api (i.e. minsdk = 21)
animateSimply () which has simple animation.

When the client uses the XYZ library , he should be able to see animateWithTransition () as a sentence (ctrl + space) if his minsdk <21. and should only be able to see animateSimply () : |

How to do it?

+3


source to share


1 answer


You should try to structure your code like this:

    public void performAnimation() {
    if(Build.VERSION.SDK_INT < 21 )
         { 
      // write code for animateSimply function here 
           }
    else
         { 
      // write code for animateWithTransition function here 
           }
        }

      



In this case, you will have one feature (which means less code, cleaner code) and easier testing. Also, your client only has to call 1 function, making it easier for your library to use.

+2


source







All Articles