Android: Fast button presses results in multiple i

2020-07-18 08:15发布

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);
        }

4条回答
看我几分像从前
2楼-- · 2020-07-18 08:28

use

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

it fixes the problem

查看更多
够拽才男人
3楼-- · 2020-07-18 08:44

Try setting the flags for the intent like

intent.setFlags(FLAG_ACTIVITY_BROUGHT_TO_FRONT);

You can also set this flag via AndroidManifest.xml file in the Application section. Prefer this method over above one.

Updating launchMode using the Manifest file

Hope this resolves your issue.

查看更多
虎瘦雄心在
4楼-- · 2020-07-18 08:47

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

查看更多
劳资没心,怎么记你
5楼-- · 2020-07-18 08:52

If i had a dime for this bug my QA filed I would be pretty rich if not a millionaire :P There are only so much one can do. Based on your implementation you could try a few things.

  1. As already mentioned, use a boolean. Set it to true once you click it and check this boolean if the button is clicked again. Set it to false once you are done.

  2. Use a progress dialog in case its a long activity like receiving data in your next activity before it displays. This also gives a hint to the user, that something is happening and he need not worry.

查看更多
登录 后发表回答