iHeartRadio 使用 Android 架構元件建立更簡潔、更精簡的程式碼集
透過集合功能整理內容
你可以依據偏好儲存及分類內容。

總部位於紐約市的 iHeartRadio 提供無限量的音樂和數千個廣播電台,全部透過一個應用程式就能完成。該公司的作業包括電台廣播、線上、行動裝置、數位和社群媒體、現場音樂會和活動、聯合發布、音樂研究服務和獨立媒體代表。
這個應用程式在 2008 年推出後,全球各地聽眾的下載次數已達 10 億次。不過,到了 2017 年底,程式碼集非常難以管理,且確實難以管理程式碼和整合新功能。
具體措施
在升級程式碼的過程中,iHeartRadio 選擇了 Android 架構元件。簡單易懂的 Room 持續性程式庫對工程師而言更有吸引力,因為其處理非同步查詢和 RxJava 等功能,而 iHeartRadio 也在程式碼中大量使用這類程式庫。
還採用了生命週期感知元件,可執行因應其他元件生命週期狀態變化的動作。iHeartRadio 工程師發現這些元件非常實用,可以縮減插入活動和片段的依附元件。此外,該公司使用 ViewModel 建立原型,在設定變更 (例如畫面旋轉) 時保留資料。
成果
iHeartRadio 發現可以輕鬆遷移至架構元件,並使用程式庫測試整合作業是否有效。Room 和其他元件需要使用極少量的樣板程式碼,因此應用程式的程式碼現在會大幅縮短。架構元件也會導致記憶體流失情形減少。另一個好處是,加入團隊的新開發人員可快速提升及開始程式設計。
整體而言,採用架構元件協助 iHeartRadio 打造出更簡潔且更精簡的程式碼集,進而防止錯誤發生。這對所有應用程式來說都是件好事,尤其是為全球目標對象提供全方位數位音訊的應用程式。
開始使用
Android 架構元件開放所有開發人員使用,這是 Android Jetpack 的一部分。開始使用 Android 架構元件。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2018-05-03 (世界標準時間)。
[null,null,["上次更新時間:2018-05-03 (世界標準時間)。"],[],[],null,["# iHeartRadio creates a cleaner, leaner code base with Android Architecture Components\n\nNew York City-based [iHeartRadio](https://www.iheart.com/) provides\nunlimited music and thousands of radio stations, all in one app. The company's\noperations include radio broadcasting, online, mobile, digital and social media,\nlive concerts and events, syndication, music-research services, and\nindependent media representation.\n\nListeners around the world have downloaded the app over a billion times\nsince it launched in 2008. By late 2017, however, the codebase was aging,\nand managing the code and integrating new features proved to be difficult.\n\nWhat they did\n-------------\n\niHeartRadio chose\n[Android Architecture Components](/topic/libraries/architecture) as they\nbegan upgrading their code. The straightforward, easy-to-implement\n[Room](/topic/libraries/architecture/room) persistency library was\nattractive to their engineers for its\ncapabilities for handling such things as asynchronous queries and support for\nRxJava, which iHeartRadio uses extensively in their code.\n\nThey also adopted\n[lifecycle-aware components](/topic/libraries/architecture/lifecycle),\nwhich perform actions in response to a change in the\nlifecycle status of another component. The iHeartRadio\nengineers found these components very useful for shrinking dependencies\ninjected into activities and fragments. In addition, the company created\nprototypes using [ViewModel](/topic/libraries/architecture/viewmodel),\nwhich allows data to survive configuration changes, such as screen rotations.\n\nResults\n-------\n\niHeartRadio found it easy to migrate over to\n[Architecture Components](/jetpack/arch)\nand to use the libraries to test how well integration was working.\n[Room](/topic/libraries/architecture/room) and other components require\nthe use of very little boilerplate code, meaning that the app's code is\nnow significantly shorter. [Architecture Components](/jetpack/arch)\nalso resulted in fewer memory leaks. An additional benefit was that new\ndevelopers joining the team could quickly get ramped up and start coding.\n\nOverall, adopting [Architecture Components](/jetpack/arch) has helped\niHeartRadio to create a cleaner, leaner code base that helps them to prevent errors.\nThat's good news for any app, especially for one offering\nall-in-one digital audio to a worldwide audience.\n\nGet started\n-----------\n\nAndroid Architecture Components is open to all developers as part of\n[Android Jetpack](/jetpack). [Get\nstarted with Android Architecture Components](/jetpack/arch)."]]