Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Fast button presses results in multiple instances of 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);
        }
like image 239
TylerKinkade Avatar asked Dec 27 '22 04:12

TylerKinkade


1 Answers

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.

like image 56
havexz Avatar answered Dec 31 '22 14:12

havexz