简体   繁体   English

应用程序因错误的活动而回到前台

[英]Application brought back to foreground with wrong activity

I have a problem with my application when it is brought back to the foreground in the case the phone went low on memory while the application was hidden: 在隐藏应用程序的情况下,手机的内存不足时,我的应用程序回到前台时遇到问题:

The class inheriting from Application is re-created ( onCreate is called again), thus losing data it held before. 将重新创建从Application继承的类(再次调用onCreate ),从而丢失其之前保存的数据。 The Activity which is restarted is not the one tagged as main action in the Manifest, but the last one that was active. 重新启动的Activity不是清单中标记为主要操作的活动,而是最后一个活动的活动。 This is a problem as the main activity, from which the user logs in, is the one responsible for filling in the Application subclass' data and I can't fill it in later. 这是一个问题,因为用户登录时所进行的主要活动是负责填写Application子类的数据的活动,以后我将无法填写。

Is there any way to tell the application to restart at the main activity instead of the latest one in this case ? 在这种情况下,是否有任何方法可以告诉应用程序在主要活动处重新启动,而不是在最新活动处重新启动?

You could check in onResume() if the user is logged in. Means that you check if your Application data is filled. 如果用户已登录,则可以签入onResume()。这意味着您要检查是否填充了应用程序数据。 If this is not the case, finish the activity and start your first Application. 如果不是这种情况,请完成活动并启动您的第一个应用程序。

The user expect to return to the latest activity, so a general "always start first activity" would upset the user... 用户希望返回到最新活动,因此一般的“总是开始第一个活动”会使用户感到不舒服。

you could keep the data by implementing methods such as onPause() and onResume() Check this link out: http://developer.android.com/reference/android/app/Activity.html 您可以通过实现onPause()和onResume()之类的方法来保留数据。请检查此链接: http : //developer.android.com/reference/android/app/Activity.html

this answer might also be helpful: onSaveInstanceState () and onRestoreInstanceState () 这个答案可能也有帮助: onSaveInstanceState()和onRestoreInstanceState()

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

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