一句话:提出系统级方案 RCHDroid,通过新建 activity 并迁移状态而非重启,让应用无需修改即可透明处理配置变更,处理时间减少 25.46%。
移动设备常发生运行时配置变更(如屏幕旋转、尺寸调整、语言切换)。Android 现有设计采用基于重启的方案加载新配置资源,开发者必须显式处理 activity 重启带来的状态保存与恢复,否则会造成状态丢失甚至应用崩溃。本文提出 RCHDroid——一种 Android 系统层面的透明运行时变更处理方法:配置变更时不重启 activity,而是按新配置创建新 activity,将状态从旧 activity 迁移到新 activity,并让旧 activity 进入非活跃模式;对仍在旧 activity 上运行的异步任务,采用惰性迁移方案,在任务返回时迁移其结果事件。作者在真实硬件上实现了原型并开源,现有应用无需任何修改即可处理运行时变更,处理时间减少 25.46%。
Mobile devices often face runtime configuration changes, such as screen orientation changes, screen resizing, and language switching. The current Android design adopts a restarting-based solution to load the corresponding resources according to the new configuration. Therefore, application developers must explicitly deal with state preservation and restoration brought about by the activity restarting. Otherwise, the runtime change will cause state loss and even app crash issues. To solve the runtime change handling issues, we propose RCHDroid, a transparent runtime change handling approach for apps at the Android system level. When a configuration change occurs, we do not restart the activity, but instead, create a new activity according to the new configuration and migrate states from the old one to the new one, while putting the old activity into an inactive mode. We propose a lazy-migration scheme to handle asynchronous tasks that remain working on the old activity, which migrates the result events when the asynchronous tasks return. We have implemented a prototype of RCHDroid with real hardware and released the source code for public access. Overall, using RCHDroid, existing apps can handle runtime configuration changes without any modifications and save the runtime change handling time by 25.46%.