In 2020, Android as well as what new look?


This article will introduce predict trends in 2020 Android everyone.

作者| Maciej Kozlowski

Translator |  meniscus , Zebian | Guo Rui

Exhibition | CSDN (ID: CSDNnews)

The following is the translation:

If you are a mobile developer, first of all keep up with the latest trends in technology, and always pay attention to new things, even if sometimes you do not even need to question their own beliefs.

Application developers on the one hand been trying to find ways to simplify and shorten the development process, on the other hand is also working to design and build the best user experience. Every year we can see the emerging mobile application developers a new and advanced technologies and tools. In this article, I will introduce a new trend in 2020, to help you better understand the most cutting-edge technology.

Kotlin coroutine

If you have not used the Kotlin coroutine, then I build you can now start to try, this is one of the best ways to perform asynchronous tasks. Since Google announced the launch of Kotlin First, use coroutine becomes a very natural thing. This tool can not only create synchronization tasks, but also has other advanced features, such as:

  • Channel (Channel)

  • Flow (Flow)

  • Continuation

In addition, there are some very practical ViewModel and LiveData expansion:

val userListLiveData: LiveData<List<User>> =
    liveData(viewModelScope.coroutineContext + Dispatchers.IO) {
        emit(repository.getUserList())
    }

fun getUserList() {
    viewModelScope.launch {
        usersLiveData.value = withContext(Dispatchers.IO) { repository.getUserList() }
    }
}

Coroutine and RxJava2

I do not intend in this article further describes the differences between the two. In simple terms, the main difference is that RxJava2 is a very powerful tool, not only for asynchronous tasks. If you ask me what the solution should be used, the answer is simple, depending on your needs, so I suggest you read a lot of documentation on these tools, make a careful decision.

theme

自 Android 10 起,Google 正式支持暗色主题。这意味着我们可以通过系统设置,将我们的应用调整为系统主题。多主题的支持已添加到许多应用中,例如 Instagram、Chrome 以及 Medium。你还可以使用1.1.0版中的 Material Components Styles 来支持 Android Q 中的暗色主题功能。不过,这个功能仍处于beta版。更多信息请点击这里(https://material.io/develop/android/theming/dark/)。

Jetpack安

在过去几年中,为了提高 Android 设备的安全性,Google 付出了巨大的努力。虽然并非每个应用都需要高级的解决方案,但是我想特别指出 Google 的这个安全库。

Jetpack 安全是一种在 Shared Preferences 中安全地存储数据的方法。最重要的是,这个库使用了Android Keystore System——最近发布了alpha版(https://developer.android.com/topic/security/data.md)。

导航组件

2018年,Google 在 Google IO上推出了导航组件(Navigation Component),并于一年后的2019年3月推出了稳定版本。

这是一种全新的设计 Android 应用导航图的方式。这个解决方案类似于 iOS 中的 Story Board。我们可以在导航编辑器中实现导航图,或编辑XML文件。导航组件支持片段事务、深层链接、SafeArgs以及视图模型范围等。

有关导航组件的更多信息,请点击这里(https://developer.android.com/guide/navigation/navigation-getting-started)。

ViewPager 2

View Pager 2 于2019年11月20日发布了稳定版本。

View Pager 2 为我们带来了很多改进:

  • 结合 RecyclerView 一起使用;

  • 支持垂直定向;

  • 新的 PageChangeCallback —— 无需重新所有3个方法;

  • 添加了不同的 Page Transformer。

class ViewPager2FragmentStateAdapter(
    fragmentManager: FragmentManager,
    lifecycle: Lifecycle,
    private val texts: List<String>
) : FragmentStateAdapter(fragmentManager, lifecycle) {

    override fun getItemCount(): Int = texts.size

    override fun createFragment(position: Int): Fragment {
        return TextFragment.newInstance(texts[position])
    }
}

如果你想了解更多有关View Pager 2的信息,请点击这里(https://medium.com/google-developer-experts/exploring-the-view-pager-2-86dbce06ff71)。

Saved State

这是一个库,可以帮助我们保存实例状态。如果 ViewModel 能够保留配置更改的话,为什么我们还需要 Saved State?因为除了配置更改之外, Android 开发人员还应该注意系统启动的进程终止。为此,我们应该将序列化的状态保存在磁盘空间中,而如今现在我们有了内置的 ViewModel。

ViewModel 的稳定版本于2019年9月发行,但RC-03版本中还有一个扩展库 ViewModel-SavedState。

class MainActivity : AppCompatActivity() {

    private val viewModel by viewModels<MainViewModel> {
        SavedStateViewModelFactory(
            application,
            this
        )
    }
}
class MainViewModel(private val savedStateHandle: SavedStateHandle) : ViewModel() {

    fun saveUserId(userId: Int) {
        savedStateHandle.set(EXTRA_USER_ID, userId)
    }

    fun getUserId(): LiveData<Int> {
        return savedStateHandle.getLiveData<Int>(EXTRA_USER_ID)
    }
}

Jetpack Compose

虽然我把 Jetpack Compose 放在了最后,但并不意味着它不重要。老实说,我对这个工具抱有很高的期望。这是一种全新的在 Android 中创建视图的方法。我们甚至应该为它的出现而欢呼。这个解决方案是一种交互式的创建UI的方式,而且是完全用Kotlin编写的!

如果你想尝试Jetpack Compose,那么可以参考这个教程(https://developer.android.com/jetpack/compose/tutorial)。

然而,Jetpack Compose 目前还处于预览阶段,甚至还没有Alpha版本。

总结

2019年,Android 的世界发生了很多大事。最令人期待的莫过于 Jetpack Compose,但距离它的稳定似乎还需要很长一段时间。也许2020年我们还看不到稳定版本上线,但是我们应该率先学习起来,因为这代表了在 Android 中构建视图的未来。

对于以上我的预测,你有何看法?如果你有不同的想法,请在下方留言。

原文:https://android.jlelse.eu/android-trends-in-2020-d6a2930596a

作者:Maciej Kozłowski,高级Android开发@Espeo Software。

本文为 CSDN 翻译,转载请注明来源出处。

热 文 推 荐 

京东回应「被薅 7000 万、项目组全体开除」;微信朋友圈屏蔽支付宝集五福;MySQL 8.0.19 发布 | 极客头条

不再设立 Flag,马克·扎克伯格的新年寄语!

PHP 可能在未来十年内消失?

铁打的春晚,流水的互联网公司

达摩院 2020 预测:模块化降低芯片设计门槛 | 问底中国 IT 技术演进

千万不要和程序员一起合租!

在调查过基于模型的强化学习方法后,我们得到这些结论

漫话:如何给女朋友解释为什么一到年底,部分网站就会出现日期混乱的现象?

你点的每个“在看”,我都认真当成了喜欢

发布了1643 篇原创文章 · 获赞 4万+ · 访问量 1338万+

Guess you like

Origin blog.csdn.net/csdnnews/article/details/103982284