我想创建一个未实现 ParcelableSpan
的 MetricAffectingSpan
,因为如果没有 Context
实例,它的状态就不容易持久化。框架是否期望所有 MetricAffectingSpan
都实现 ParcelableSpan
?我担心我的类的实例会被 Android 框架强制转换为 ParcelableSpan
,尽管一切似乎都正常。
我不确定如何将框架引入 parcelling span。我尝试使用 StyleSpan
进行测试,但从未见过调用 Parcel
实例的构造函数。
最佳答案
我会说是的,它是安全的。 Parceling 用于在 Activity 之间或进程之间传递状态。
由于自定义跨度信息在共享时会导致其他进程崩溃,因此不实现它甚至可能是个好主意。
You can’t create your own ParcelableSpan. To avoid crashes due to unknown data types, the framework doesn’t allow implementing custom ParcelableSpan, by defining two methods, getSpanTypeIdInternal and writeToParcelInternal, as hidden. Both of them are used by TextUtils.writeToParcel.
Google 自己的 Florina Muntenescu https://medium.com/androiddevelopers/underspanding-spans-1b91008b97e4
关于android - 创建一个不实现 ParcelableSpan 的 MetricAffectingSpan 是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46347772/