Replace or treat obsolete method

3

I'm updating an Android application and I came across the following situation:

  • I have a minimum sdk of 21 and a target of 27.
  • A method that was obsolete version 24.

My question is: what is the best way to fix an obsolete method?

  • Replace old method with new?
  • Try to have the old method perform its function for android versions prior to 24 and the new method make the other versions? (a simple if / else comparing the api versions of the cell to that of the method.)

    if{versão atual > 24){ //Executa método novo. }else{ //Executa método antigo. }

asked by anonymous 10.07.2018 / 15:39

1 answer

4

It depends.

  • The class that has this method exists in a compatibility library.

    • Use this class and keep the library updated.
  • The class does not exist in the compatibility library.

    • The method adds features in the latest versions.

      • Use if(versao) and use the corresponding method.
    • The method does not add functionality.

      • If the target is to maintain, you can use the old method.
      • If the target is to be updated to the latest version, while compiling can use the old method. If you stop compiling and condition 2 holds, use if(versao)
  • minSdk can be increased with minimal impact on application reach.

    • Change minSdk and use the new method.
  • 10.07.2018 / 16:48