如下android doc里面的原文
Generally, you should not use onPause()
to store user changes (such as personal information entered into a form) to permanent storage. The only time you should persist user changes to permanent storage withinonPause()
is when you're certain users expect the changes to be auto-saved (such as when drafting an email). However, you should avoid performing CPU-intensive work during onPause()
, such as writing to a database, because it can slow the visible transition to the next activity (you should instead perform heavy-load shutdown operations during onStop()
).
一般来说,我们不需要再onPause的时候将例如一个表单内容保存到物理内存中。只有当你确认一个用户引发的变化是必须被自动保存的时候,例如正在看一份邮件时,你就需要在onPause时保存这个邮件信息了。然而,在onPause的时候只适合做一些占用cpu极短时间的动作,例如写数据库就是一个耗时的工作,你应该在onStop的时候干这个事情