0

In my app, i have two buttons that send an event with an ID using an event bus (Otto). Depending on this ID, the app goes to a different level of the navigation between differents fragments. Is possible to avoid that the event bus sends the same event (with different ID) in the same millisecond when the user taps over two different button at the same millisecond?. I attach an image in order to show my Logcat.

Thanks!

enter image description here

EDIT 1:

Using syncronized both onClick method as subscribe method, i continue receiving the events in the same millisecond. Now, the myth about "syncronized" has down for me. O_o

There are posts where they explain how avoid very fast clicks, but here, the clicks are in the same millisecond...rare, but you can see the logs.

I attach new images with the method that i am using. Thanks! enter image description here

enter image description here

enter image description here

juanjo
  • 87
  • 1
  • 8

1 Answers1

0

Yes, use synchronized keyword with the method which is generating events (or also with the method which receive events).

For example:

public synchronized void genEvent(){

}

See following related links

https://docs.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html

When to use synchronized in Java

Is there an advantage to use a Synchronized Method instead of a Synchronized Block?

Community
  • 1
  • 1