Android 杀死它后重新启动应用程序 [英] Restart application after Android kills it

查看:61
本文介绍了Android 杀死它后重新启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,Android 会在一段时间后杀死应用程序,如果用户不与其交互,以节省内存.如果用户返回应用程序,再次显示最后一个活动.我想做的是,当这种情况发生时,我总是想从我的主要活动重新开始.但只有当我的应用程序被杀死,而不是在其他情况下.

As far as I know, Android kills an application after sometime if the user is not interacting with it, in order to save memory. If the user goes back to the application, the last activity is displayed again. What I would like to do is that when this situations occurs, I always would like to restart from my main activity. But only if my application was killed, not in other scenarios.

有没有办法做到这一点?例如在清单中?

Is there any way to do that? in the manifest for example?

提前致谢!

推荐答案

可以通过检查onCreate方法中的bundle是否为空来判断一个Activity是否已经恢复:

You can check whether an Activity has been resumed by checking if the bundle in the onCreate method is null:

if(savedInstanceState != null)

如果它不为空,则您的活动已从被杀死状态恢复.

If it isn't null, your activity has been resumed from being killed.

如果您只是暂停您的活动 onResume() 将通过 onCreate() 调用.

If you're simply pausing your activity onResume() is called over onCreate().

有关活动生命周期的信息,请参阅此处的文档.

See the documentation here for the Activity Lifecycle.

这篇关于Android 杀死它后重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆