简体   繁体   English

即使在Android中关闭了屏幕,如何保持应用状态?

[英]How to keep app status even if screen is turned off in Android?

I've a problem with my app, when I press side standby(screen disable) button when app is opened and turn on screen again and unlock my app is now in background, also, when I reopen it from background it restarts with loading screen(so it loose my previous app state and reset it). 我的应用程序有问题,当我在打开应用程序并再次打开屏幕并解锁时按侧面待机(屏幕禁用)按钮时,现在我的应用程序处于后台状态;当我从后台重新打开应用程序时,它会在加载屏幕时重新启动(因此它会释放我以前的应用状态并进行重置)。 But when I place my app in background going to home and reopen it, it start from where it was when it goes in background. 但是,当我将我的应用程序置于后台并重新打开时,它从后台运行时的位置开始。 Same if I close screen when app is already in background. 如果应用程序已经在后台时关闭屏幕,也是如此。

How can I solve this problem? 我怎么解决这个问题?

Android usually keeps your app on the foreground even if you press on the power button (side standby). 即使您按下电源按钮(侧面待机),Android通常也会使您的应用程序处于前台。 Try using the SavedInstance as mentioned by Abo Hani. 尝试使用Abo Hani提到的SavedInstance。

Otherwise, Try testing the app on other devices with different android versions. 否则,请尝试在具有不同Android版本的其他设备上测试该应用程序。

Android only sends apps to the background if it needs more resources(memory,network,etc) to process other apps. Android仅在需要更多资源(内存,网络等)来处理其他应用程序时才将应用程序发送到后台。 Sometimes it might also kill the app. 有时它也可能会杀死该应用程序。

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

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