• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I prevent my clipboard monitor to copy the clipboard data twice?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been working on a simple clipboard monitor that saves the content of the clipboard on a file text when there is a change in the clipboard. Everything works fine but I noticed that whenever I copy something, the text is copied twice in succession. It as if the function is called twice in rapid succession and I can't seem to understand why?

 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do your logs show?
Is the trigger firing twice?
 
Rachid Insa
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:What do your logs show?
Is the trigger firing twice?



This is what my logs show (in the file attacched), in this case the word copied is "database".

1.PNG
[Thumbnail for 1.PNG]
log
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add some logging for the create/destroy, around the add/remove of the listener.
Either the callback is fired twice for an event (unlikely) or there are two listeners.

Actually, when logging in the ClipChanged, could you include the class?

That (hopefully) would print the default toString.

ETA:  Also, it's preferable to copy and paste text here, rather than include images.
It's a lot easier for us to work with text.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also print the value of mNow and the value of Date with the current time Ie without any arg: Date()
 
Rachid Insa
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Add some logging for the create/destroy, around the add/remove of the listener.
Either the callback is fired twice for an event (unlikely) or there are two listeners.

Actually, when logging in the ClipChanged, could you include the class?

That (hopefully) would print the default toString.

ETA:  Also, it's preferable to copy and paste text here, rather than include images.
It's a lot easier for us to work with text.



I added the logging as requested and this is what I got:




As you can see it works for the first element "oui c'est vrai" but not for the second element copied "are no longer" which is copied twice. What I actually noticed is that it actually copies things twice only when I copy from the browser, indeed the first element was copied from another application (Twitter).
 
Rachid Insa
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Norm Radder wrote:Also print the value of mNow and the value of Date with the current time Ie without any arg: Date()



I didn't really get you , you want me to write mNow in another way is that it?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted to see what the time was when the value of mNow was saved and the the time when the run method was executed.  
I now see that there are times in the logcat so only the value of mNow would be needed.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show the listener again?
The log line isn't referencing the class I expected.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actual, forget that.
I'm misreading things.

OK, so you have just the one listener involved here (which was the most likely result, but at least we confirmed it).

Have to ponder a bit.
 
Rachid Insa
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Actual, forget that.
I'm misreading things.

OK, so you have just the one listener involved here (which was the most likely result, but at least we confirmed it).

Have to ponder a bit.



Concerning my probem I found out that it depends on the application, Not all apps follow the rules. Sometimes an app will update the clipboard multiple times, such as once for each data format, when the user has only done the action once.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh right.
How odd.

Thanks for coming back with the information, though.
 
reply
    Bookmark Topic Watch Topic
  • New Topic