有没有办法手动设置 savedInstanceState Bundle ?
我需要在 savedInstanceState 模式下启动一个活动,在 onCreate 中 savedInstanceState Bundle 不会为 null 。我的观点是使用我的自定义数据恢复活动。谢谢
有没有办法手动设置 savedInstanceState Bundle ?
我需要在 savedInstanceState 模式下启动一个活动,在 onCreate 中 savedInstanceState Bundle 不会为 null 。我的观点是使用我的自定义数据恢复活动。谢谢
这将使您的代码不可读并且将来难以维护。此外,您将针对平台的架构工作。
正确的做法是在启动 的 Intent 中发送数据,或者如果 bundle 为 null,则Activity
获取其中的所有数据,如下所示:onCreate
if(savedInstanceState == null)
//Get data from db, resources etc.
else
//Do the restoring using the bundle,
//or just let it pass here and handle it in
//`onRestoreInstanceState`, both are correct
请不要仅仅因为以正确的方式做这些事情需要更多的时间,就试图找到黑客修复。未来一定会得到回报!:-)
作为旁注,请记住,Intent
启动一个Activity
不应包含大块数据,因为一次在组件之间传输的数据有 1mb 的跨进程限制。