简体   繁体   中英

Stop calling onDestroy method after pressing the home button in Nexus 7" tab

最近两天以来我一直遇到问题。实际上,当我在除“ nexus”选项卡之外的任何其他设备上运行我的应用程序时,按下主屏幕按钮后,不会调用onDestroy()方法。对我来说很好,但是在同一应用程序中运行时nexus选项卡上按下主页按钮后会调用onDestroy()方法。我想,我不想在按下home按钮后在nexus 7中调用onDestroy()方法。请解决我的问题。

Don't rely on onDestroy() being called. You should do everything you need in onPause() instead.

From the onDestroy() docs:

Note: do not count on this method being called as a place for saving data! For example, if an activity is editing data in a content provider, those edits should be committed in either onPause() or onSaveInstanceState(Bundle), not here.

You don't get to decide that. As soon as your app goes into onPause Android can reclaim the resources used by your app by killing your app and going through onDestroy . You need to override the lifecycle events and handle saving the data necessary within them to prevent this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM