Replace or process obsolete method

Asked

Viewed 32 times

3

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

  • I have a minimum sdk of 21 and target of 27.
  • A method that has been deprecated version 24.

My question is this: what is the best course of action to correct an obsolete method?

  • Replace old method with new?
  • Treat so that the old method performs its function for android versions prior to 24 and the new method performs the other versions? (a simple if/Else comparing mobile’s api versions to the method.)

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

1 answer

4

Depends.

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

    • Use this class and keep the library up to date.
  2. Class does not exist in the compatibility library.

    • The method adds features in the latest versions.

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

      • If the target for keeping, you can use the old method.
      • If the target is to be upgraded to the latest version, while compiling can use the old method. If you fail to compile and condition 2 remains, use if(versao)
  3. The minSdk can be increased with minimal impact on the scope of the application.

    • Change the minSdk and use the new method.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.