关于活动生命周期
在我的应用中,我覆盖了 onPause()
函数,但是它不起作用,并且 onStop()
仍然被调用。任何建议表示赞赏,谢谢!
@Override
protected void onPause()
{
if(the activity did not meet my requirements)
this.onResume();
else
super.onPause();
}
In my app, I overwrited the onPause()
function, however, it didn't work, and onStop()
was still invoked. Any advice is appreciated, thx!
@Override
protected void onPause()
{
if(the activity did not meet my requirements)
this.onResume();
else
super.onPause();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你不能直接调用
onResume()
或onPause();。
它们是回调方法,由系统调用。I think you can not directly call
onResume()
oronPause();.
They are callback methods and are invoked by system.阻止系统暂停您的应用程序通常是一个坏主意,因为每当调用该方法时,就意味着用户现在不想使用您的应用程序。这个原因可能是正在打电话、切换到另一个应用程序、退出等。Android 仍然会认为您的应用程序已暂停并执行它想要的操作(和设计目的)。更好的解决方案是保存应用程序在
onPause()
上所处的任何状态,然后在用户返回时在onResume()
中恢复状态。It's generally a bad idea to prevent the system from pausing your application because whenever that method is invoked it means the user doesn't want to use your application right now. That reason could be a phone call is starting, switching to another app, backing out, etc. Android is still going to think your application is paused and do what it wants (and designed to do) with it. A better solution would be to save whatever state your application is in on
onPause()
, then restore the state inonResume()
if/when the user comes back.