Android:快速按下按钮会导致多个意图实例(Android: Fast button presses results in multiple instances of intent)

编程入门 行业动态 更新时间:2024-10-08 02:17:26
Android:快速按下按钮会导致多个意图实例(Android: Fast button presses results in multiple instances of intent)

目前我遇到了一个错误,如果用户快速点击一个按钮,按钮附加的意图将多次触发,导致该意图的堆栈需要再次追溯。 我怎样才能避免这种情况或解决这个问题?

谢谢~k

这是onClickListener的内部。 我在这里设置布尔值,然后在进程结束时取消设置。

if(!isDating) { intent.setClass(context, EventDate.class); isDating = true; ((TabGroupActivity) context).startChildActivity("EventDate",intent); }

Currently I'm experiencing a bug where if the user quickly taps a button, the intent that the button is attached to will fire off multiple times, resulting in a stack of that intent that will need to be back traced through again. How can I avoid this or remedy this?

Thanks ~k

This is inside of the onClickListener. I set the boolean value here, then I unset it at the end of the process.

if(!isDating) { intent.setClass(context, EventDate.class); isDating = true; ((TabGroupActivity) context).startChildActivity("EventDate",intent); }

最满意答案

尝试为意图设置标志

intent.setFlags(FLAG_ACTIVITY_BROUGHT_TO_FRONT);

您还可以通过Application部分中的AndroidManifest.xml文件设置此标志。 首选此方法。

使用Manifest文件更新launchMode

希望这能解决你的问题。

Actually I found a better solution!

by setting the onClickListener(null); then recreating it onResume, it bypasses having to use flags and what not.

!k

更多推荐

本文发布于:2023-08-07 12:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464141.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   按下   意图   实例   按钮

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!