Each year there’s a new version of the Android SDK released. Along with the myriad of new features come deprecations. When something is deprecated, although it’s still available, it’s best to migrate to the recommended new API. With that being said here are some common deprecations I encountered in my company’s Android codebase and how to fix them.
Deprecated Menu APIs on Fragments
The Fragment APIs for providing a menu to your activity’s ActionBar
have been deprecated as they tightly couple your fragment to your activity and are not testable in isolation. The new MenuHost
and MenuProvider
APIs provide a testable, lifecycle-aware equivalent API surface that fragments should use instead.