返回按钮重新打开活动
有几次,当用户按下我的应用程序上的后退按钮时,不幸的是他没有退出; Activity 滑动了,但后面却是一模一样的……这怎么可能?我怎样才能避免呢?我应该为 onBackPressed() 方法实现一些东西吗? 感谢您的建议。
There are a few times when the user presses the back button on my app, and unfortunately he doesn't get out; the activity slides, but behind it there is exactly the same one...How is that possible? How could I avoid it? should I implementate something for the onBackPressed() method?
Thanks for your advices.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不必执行 onBackPressed。这听起来像是正在创建/启动该活动的多个实例,这是调用 .startActivity() 时预期的默认行为 查看文档 任务和返回堆栈。
您可以使用 singleTop 作为启动模式或设置
Intent.FLAG_ACTIVITY_SINGLE_TOP
关于启动活动的意图。
You don't have to do implement onBackPressed. This sounds like multiple instances of the activity are being created/started, which is expected default behaviour when calling .startActivity() Check out the docs Tasks and Back Stack.
You could use singleTop as the launchmode or set the
Intent.FLAG_ACTIVITY_SINGLE_TOP
on the intent that launches the activity.
您可以在
Manifest
中使用android:launchMode="singleTop"
您的活动减速。you can use
android:launchMode="singleTop"
your activity deceleration in theManifest
.