What’s deprecated in Android Jetpack 2019

매년 사라져가는 Android API를 기념하여 글을 작성합니다.

Sungyong An
9 min readDec 28, 2019

올해에도 여러가지 API가 Deprecated 되었습니다.
문득 연말이 되니 어떤 것들이 바뀌었었는지 회고해보고 싶은 마음에
글을 작성하게 되었습니다.

정보성 글이라기보다는 단순히 재미로 보시면 좋을 것 같습니다. 🤣

Medium은 코드가 예쁘게 나오지 않아, API diff는 이미지로 첨부합니다.
색상에 따라 대략 Deprecated / New / Alternative API로 생각하면 됩니다.

car, ui(=compose)에 대한 내용은 제외합니다.

Deprecated Android Jetpack API를 가볍게 살펴봅시다. 🏃‍♂️️️🏃‍♂️🏃‍♂️

LocalBroadcastManager 📢

Deprecate LocalBroadcastManager

localbroadcastmanager:1.1.0 (aosp/819673)

더이상 LocalBroadcastManager 사용을 권장하지 않습니다.
LiveData나 Reactive Stream 등을 이용해서 비슷한 기능을 직접 구현해서 쓰는것을 권장하네요.

Fragment 🧩

가장 Deprecated가 많았던 기능입니다.
부디 2020년에는 더 좋은 방향으로 수정되기를 기원합니다. 🧧

Deprecate FragmentTabHost

fragment:1.1.0 (aosp/930457)

FragmentTabHost 대신 TabLayout과 ViewPager를 사용하는 것을 권장합니다.
다만 ViewPager도 Deprecated에 가까워진 느낌이므로,
이제는 ViewPager2를 사용하는 것을 추천합니다.

Deprecate setUserVisibleHint()

fragment:1.1.0 (aosp/945776)

ViewPager 내부의 Fragment가 사용자에게 표시되고 있는지 구분할 때 사용할 수 있는 getUserVisibleHint()가 Deprecated되었습니다.

Deprecate setTransitionStyle in FragmentTransaction

fragment:1.2.0 (aosp/1011537)

Fragment의 TransitionStyle이 제거됩니다.

Deprecate Fragment breadcrumb related APIs

fragment:1.2.0 (aosp/1090298)

Breadcrumb API도 제거됩니다.

Deprecate Fragment getFragmentManager and requireFragmentManager

fragment:1.2.0 (aosp/1115082)

getFragmentManager(), requireFragmemtManager() 대신 getParentFragmentManager()를 사용하세요.

Deprecate setRetainInstance() method in Fragment

fragment:1.3.0 (aosp/1159084)

더이상 Retain Instance를 사용하지 마세요.

필요한 경우에는 AAC ViewModel에 상태를 저장하세요.

Deprecate Fragment ViewPager adapters

fragment:1.3.0 (aosp/1173772)

더이상 ViewPager에서는 Fragment를 사용하지 마세요.

ViewPager2를 사용하세요.

ViewPager와 달리 ViewPager2는 내부적으로 RecyclerView를 사용합니다.

Deprecate Fragment’s onActivityCreated

fragment:1.3.0 (aosp/1189651, NOT Merged Yet)

아직 반영되지 않은 내용입니다.
Fragment#onActivityCreated()를 상속하지 않는 것을 권장합니다.

  • View 생성과 연관된 경우는 Fragment#onViewCreated()에서 생성하고
  • 외부 참조가 필요할 때는 FragmentFactory를 통해 매개변수로 전달하고
  • 이외에는 onCreate()에서 초기화하는 것을 고려해보세요.

Navigation 🚀

Deprecate FragmentNavigator.instantiateFragment

navigation:2.1.0 (aosp/930120)

아마도 FragmentNavigator를 직접 바라본 경우는 없을 것 같지만,
FragmentFactory가 추가되면서 사용하지 말 것을 권장합니다.
FragmentFactory를 통해 생성하고, Argument를 별도로 전달해주세요.

Lifecycle 🔗

Deprecate ViewModelProviders

lifecycle:2.2.0 (aosp/985148, aosp/1009889)

ViewModelProviders가 Deprecated 되었습니다.

ViewModelProvider 생성자를 직접 호출하세요.

Kotlin 언어에서는 ktx가 제공됩니다.

자세한 것은 링크를 참고하세요.

Room 🏠

Deprecate OnConflictStrategy.ROLLBACK and FAIL

room:2.1.0 (aosp/839274)

Insert가 실패할 때, ROLLBACK과 FAIL을 더이상 사용할 수 없습니다.

ABORT가 ROLLBACK과 동일하게 동작하므로, ABORT를 쓰세요.

Deprecate RoomDatabase transaction methods.

room:2.1.0 (aosp/900916)

Room Transaction은 모두 runInTransaction() API를 사용하세요.

Work 👷‍♂️

Deprecate `coroutineContext` in CoroutineWorker.

work:2.1.0 (aosp/940705)

WorkManager에서도 약간의 변화가 있습니다.
CoroutineWorker를 사용한다면 doWork() 내에서 withContext(…)로 CoroutineContext를 직접 제어하는 것을 권장합니다.

RecyclerView️️ ♻️

Deprecate RecyclerView#setLayoutFrozen(boolean)

recyclerview:1.1.0 (aosp/839414)

함수명이 suppressLayout(boolean)로 변경되었습니다.

Collection 🗂

Deprecate redundant delete method

collection:1.1.0 (aosp/866053)

더이상 LongSpareArray, SparseArrayCompatdelete() API를 쓰지 마세요.
대신 remove() API를 사용하면 됩니다.

Preference ⚙️

Deprecate Preference#onInitializeAccessibilityNodeInfo

preference:1.1.0 (aosp/983606)

Preference는 View가 아니므로, 더이상 접근성을 지원하지 않습니다.
필요하다면 Preference#onBindViewHolder()에서 접근성을 직접 설정하도록 권장하고 있습니다.

Media2 🎶

Deprecate MediaPlayer#NO_TRACK_SELECTED

media2:1.1.0 (aosp/1011652)

MediaPlayer2#getSelectedTrack() API가 Nullable로 변경되고,
NO_TRACK_SELECTED는 더이상 사용하지 않습니다.
적절히 null 조건문을 추가해야 합니다.

Browser 👀

Deprecate Browser Actions

browser:1.2.0 (aosp/926816)

BrowserActionsIntent가 Deprecated 되었습니다.
대신 CustomTabsIntent를 사용하면 됩니다.

지금까지 2019년도에 Deprecated된 Android Jetpack API들을 살펴봤습니다.
내년에는 또 어떤 API가 Deprecated 될지 기대됩니다. 🤣

다음에는 Platform에서 Deprecated된 API를 간단히 살펴보겠습니다.
그럼 즐거운 연말되세요. 🎉🎉🎉

--

--