返回按钮重新打开活动

发布于 2024-12-29 15:33:37 字数 120 浏览 1 评论 0原文

有几次,当用户按下我的应用程序上的后退按钮时,不幸的是他没有退出; 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℉服软 2025-01-05 15:33:37

您不必执行 onBackPressed。这听起来像是正在创建/启动该活动的多个实例,这是调用 .startActivity() 时预期的默认行为 查看文档 任务和返回堆栈。
您可以使用 singleTop 作为启动模式或设置 Intent.FLAG_ACTIVITY_SINGLE_TOP
关于启动活动的意图。

Intent detailsIntent = new Intent(mContext, DetailsActivity.class);
detailsIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
startActivity(detailsIntent);

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.

Intent detailsIntent = new Intent(mContext, DetailsActivity.class);
detailsIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
startActivity(detailsIntent);
酒与心事 2025-01-05 15:33:37

您可以在 Manifest 中使用 android:launchMode="singleTop" 您的活动减速。

you can use android:launchMode="singleTop" your activity deceleration in the Manifest .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文