Android Weekly Notes #406

Android Weekly Issue #406

A first look at AndroidX Activity Result APIs

ActivityResultContract.

有一些内置的实现可以选择: 打电话, 照相, 请求权限, StartActivityForResult等.

prepareCall方法.

官方文档中的例子:

val dial = prepareCall(Dial()) { success ->
    // Handle success or failure
}

override fun onCreate(savedInstanceState: Bundle?) {
    // ...

    val dialButton = findViewById

测试见文档: https://developer.android.com/training/basics/intents/result#test

Jetpack Compose: State

@Model@Composable.

Data Privacy for Android

  • 请求权限
  • IPC: app间.
  • opt out选项.
  • 清除缓存.
  • log信息.
  • 禁止截图.
  • 加密.
  • 生物认证.

关闭键盘缓存:

android:inputType="textNoSuggestions|textVisiblePassword|textFilter"

网络请求的cache.
webview的cache.

A Subtle Memory Leak - Fragment, RecyclerView and its Adapter

Fragment被onDestroyView了但是泄漏了.

Fragment中存有adapter的强引用.

解决办法:

    1. adapter=null
    1. recyclerView.adapter=null.

Make impossible states impossible

functional domain modelling.

目的: make impossible states impossible.
利用静态语言编译器来确保model都是正确的.

举例: user profile.
最后改造成这样:

data class UserProfile(
    val name: UserName,
    val age: Age,
    val accountType: AccountType,
    val contactInfo: NonEmptySet
)

其实基本思路就是为字段建立类型, 枚举或者是sealed class.

提到一个库: Arrow:
这是一个kotlin的库: https://arrow-kt.io/
github: https://github.com/arrow-kt/arrow

Speeding up the detekt task in a multi-project Gradle build

multi-project的gradle build中, detekt加速方法: 放在根目录.

Random Musings on the R Developer Preview 2

Android R的一些看法.

Unit Testing Delays, Errors & Retries with Kotlin Flows

Kotlin Flow的使用和单元测试.

  • runBlocking
  • runBlockingTest: 可以自己控制虚拟时间.

Implementing the Motion System With Material Components for Android

The motion system还在beta阶段.

Android's Built-in ProGuard Rules: The Missing Guide

解释Android内置的proguard rules.

这篇文章强烈推荐.

Defending Your In-Background App When Android OS Kills It

模拟系统杀死App:

adb shell am kill `

这个只会杀死可以安全被杀死的进程来释放资源.

这个命令是无情杀死:

adb shell kill

Code

一个查看room数据库的工具: https://android.jlelse.eu/exploring-android-room-database-with-room-explorer-4d760fdea9de

居然是在app里显示出来了.

一个Android构架sample:
https://github.com/PatilShreyas/Foodium
用了最新的MVVM, 协程那些技术.

你可能感兴趣的:(Android Weekly Notes #406)