简体   繁体   English

Android 在系统杀死应用程序后没有重新打开以前的活动

[英]Android is not reopening previous activity after system has killed app

I've searched SO for this but all I can find is people having the opposite problem - they want their app not to reopen to the previous activity, whereas I'm trying to figure out why my app is starting from the main activity every time I reopen it after the system has killed it for memory.我已经为此搜索过,但我能找到的只是人们遇到相反的问题-他们希望他们的应用程序不要重新打开上一个活动,而我试图弄清楚为什么我的应用程序每次都从主要活动开始在系统为 memory 杀死它后,我重新打开它。

My problem: I have an activity where the user creates data that eventually gets persisted.我的问题:我有一个活动,用户创建的数据最终会被持久化。 When I close the app with unsaved data in this activity, and then go and open other apps so that the system needs to kill my app to free memory, I'm losing my data.当我在此活动中关闭未保存数据的应用程序,然后 go 并打开其他应用程序以便系统需要终止我的应用程序以释放 memory 时,我丢失了我的数据。 I am using onSaveInstanceState/onRestoreInstanceState correctly (the data is not lost when I change orientation or turn on power-saving mode), so I know I'm saving the instance data correctly, the problem is that Android is not opening my app to this activity when I restart, so I never have a chance to restore the instance data I saved.我正在正确使用 onSaveInstanceState/onRestoreInstanceState(当我改变方向或打开省电模式时数据不会丢失),所以我知道我正在正确保存实例数据,问题是 Android 没有打开我的应用程序重新启动时的活动,所以我永远没有机会恢复我保存的实例数据。

Any idea why my app would not be opening to the last activity I left it on before the system killed it?知道为什么我的应用程序在系统杀死它之前不会打开我离开它的最后一个活动吗? Thanks.谢谢。

After the system kills your app, whatever you stored in onSaveInstanceState is deleted, too.系统杀死您的应用程序后,您存储在 onSaveInstanceState 中的任何内容也会被删除。

To save state after your app being killed use Shared Preferences or any other Persistent Storage that fits your needs.要在您的应用程序被终止后保存 state,请使用共享首选项或任何其他适合您需要的持久存储

You should save your state in onStop And check for a saved state in your onCreate to restore it if there is one您应该在onStop中保存您的 state 并在您的onCreate中检查已保存的 state 以恢复它(如果有的话)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 系统已在Android中将其关闭后,如何在重新打开活动后使服务更新活动上的UI - How to make a service update the UI on an activity after reopening after the system has shut it down in Android 如何恢复不是启动器活动的特定活动,并在系统杀死应用程序后立即导航到该活动 - How to restore a specific activity that is not the launcher activity and instantly navigate to it after the system has killed the app 系统终止应用程序进程后从头开始重新启动活动 - restart activity from from scratch after system killed the app process 活动在后台被杀死后应用程序崩溃 - App crash after activity has been killed in background Android Activity被杀死vs App被杀死 - Android Activity Killed vs App Killed 如何检查onCreate是否已杀死同一活动的先前android进程? - how to check in onCreate that the previous android process of the same activity has been killed? 应用程式被杀死后,片段仍然存在(Android) - Fragment is still alive after app has been killed (Android) Android应用重新打开后显示白屏 - Android app shows white screen after reopening 重新打开应用程序后,Android SharedPreferences无法保存 - Android SharedPreferences does not save after app reopening Android:应用程式在关闭并重新开启后当机 - Android: App crashes after closing and reopening
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM