You Are Here:

Community: Developer Discussion Boards

#1 Old commandAction called twice - 2008-11-08, 16:33

Join Date: Jul 2007
Posts: 40
Location: Paris, France
olan75
Offline
Registered User
Hi
I have a form with a command that gets invoked via the center button (this is a Series 40 6131 NFC).

I noticed (after some hair pulling) that when the user presses the center button commandAction sometimes gets called twice.
Apparently this must be because the button sometimes rebounds. I am even able to do this myself by pressing the button very fast.

This happens only on certain forms, I don't know why. Maybe it has to do with the time it takes for the form to process the first click? If the 2nd click comes when the form is still showing, commandAction gets called again?

Has anyone else noticed this?

My workaround for now is to have a flag that I set to true when processing the command, so that I can ignore it the second time.

Has anyone got an opinion on this?

Thanks!
Last edited by olan75 : 2008-11-08 at 16:34. Reason: more info
Reply With Quote

#2 Old Thumbs up Re: commandAction called twice - 2008-11-10, 06:04

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Hi,
This situation I never face..anyways your opinion is quite good and you surely can fix the underlined issue in that way.
I guess it should not be happen as you have seen.
Thanks,


Thanks

R a j - The K e r n e l
Reply With Quote

#3 Old Re: commandAction called twice - 2008-11-10, 14:53

Join Date: Feb 2006
Posts: 64
Pradeepcg's Avatar
Pradeepcg
Offline
Regular Contributor
Are you sure that the CommandAction is called 2wice?
Coz for each press CommandAction is called only once.
Have a Loading/Wait screen once you click on the desired key, so that the computation is done before the user cliks again or wants to do something else


Thanks and Regrads
Pradeepcg
Reply With Quote

#4 Old Re: commandAction called twice - 2008-11-11, 06:03

Join Date: Jul 2008
Posts: 329
Location: Faridabad(Delhi NCR)
Send a message via MSN to ansh.chauhan Send a message via Yahoo to ansh.chauhan
ansh.chauhan's Avatar
ansh.chauhan
Offline
Regular Contributor
Can YOu Write uR code so that I can check wheres the problem is cuming becoz i had never face such kind of problem


Anshu Chauhan
J2me Developer
Reply With Quote

#5 Old Re: commandAction called twice - 2008-11-11, 11:52

Join Date: Jul 2007
Posts: 40
Location: Paris, France
olan75
Offline
Registered User
Ok I'll post a sample here as soon as I can.
Reply With Quote

#6 Old Thumbs up Re: commandAction called twice - 2008-11-11, 12:18

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Hi olan75,
You can test the same code on the some other devices and check whether the commandAction is gettng called 2wiice or not.
Thanks,


Thanks

R a j - The K e r n e l
Reply With Quote

#7 Old Re: commandAction called twice - 2008-11-11, 13:48

Join Date: Oct 2008
Posts: 9
msathiskumar
Offline
Registered User
Hi,
i have also faced the similar problem.when developing a canvas with ok button.
when i select the ok softkey it used to trigger command action only once.
but in case if i select the center button it used to call it twice..
it happens only for that canvas screen also..
i am testing the app on E61i..
Reply With Quote

#8 Old Re: commandAction called twice - 2008-11-12, 05:44

Join Date: Jul 2008
Posts: 329
Location: Faridabad(Delhi NCR)
Send a message via MSN to ansh.chauhan Send a message via Yahoo to ansh.chauhan
ansh.chauhan's Avatar
ansh.chauhan
Offline
Regular Contributor
HEy Guys until u write ur sample code we cant help u..may b problem is in ur code


Anshu Chauhan
J2me Developer
Reply With Quote

#9 Old Re: commandAction called twice - 2009-01-10, 01:33

Join Date: Jul 2007
Posts: 40
Location: Paris, France
olan75
Offline
Registered User
This old article talks about it too !
http://developer.sonyericsson.com/si...p_tips1102.jsp

It happens to me all the time when I do this :

Code:
commandAction( Command c, ... )
{
  if( c == cmdOk )
  {
    otherScreen = new FunkyScreen();
    display.setCurrent( otherScreen );
  }
}
and FunkyScreen takes a while to construct itself.
Then if the button bounces, during construction of FunkyScreen I am still on the previous
screen and commandAction will be called again with cmdOk.

Therefore I have to guard against bouncing buttons in almost every screen !

I was just wondering why almost no one talks about this. Is everyone out there
doing things differently from me so that they don't experience this problem?
Reply With Quote

#10 Old Re: commandAction called twice - 2009-01-10, 02:38

Join Date: Jan 2008
Posts: 533
Location: Amravati, India
arpit2agrawal
Offline
Super Contributor
Quote:
Originally Posted by olan75 View Post
Then if the button bounces,
I didn't observe that button bounces automatically at software level. I have observed this behavior only if user has pressed the key twice very fast.
I was into hardware development also. At the hardware level, there is switch bouncing which is handled by operating system.
Which phone model did you observe this...

Anyways, I don't know whether these commandAction calls are serialized or not.

Case 1: commandAction calls are serialized
You may check if current Displayable if equal to Displayable in parameter to commandAction. If it's equal then only process the command.

Case 2: commandAction calls are not serialized
You may use synchronization to serialize commandAction calls and then do whatever is written above in Case 1.
Reply With Quote

#11 Old Re: commandAction called twice - 2009-01-10, 05:00

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
Hmmmm... commandAction() should not be called again when it is already running.

An important point you give is "if (the action) takes a long time"... it shouldn't. You must return from event handlers as quickly as possible. If something takes a long time to do, dispatch a Thread to handle it.

The Sony example you give is quite specific. It's not about key bounce, it's about event queuing. Also, key handling on the T610 is extremely poor. The Java implementation on the T610 is absolute garbage. Commands routinely throw NullPointerExceptions, keyPressed() receives codes that are invalid to getGameAction(), select-events in Lists generate multiple commandAction events. It's crap. Nokia's implementation is HUGELY better.
Reply With Quote

#12 Old Re: commandAction called twice - 2009-01-10, 15:07

Join Date: Jul 2007
Posts: 40
Location: Paris, France
olan75
Offline
Registered User
Quote:
Originally Posted by arpit2agrawal View Post
I didn't observe that button bounces automatically at software level. I have observed this behavior only if user has pressed the key twice very fast.
Which phone model did you observe this...
Not sure what you mean by "at software level", but, yes, as I described, it happens when the user presses the button twice in rapid succession, consciously or not...

This is on a Nokia 6131 and also 6212.

Quote:
Originally Posted by arpit2agrawal View Post
Anyways, I don't know whether these commandAction calls are serialized or not.

Case 1: commandAction calls are serialized
You may check if current Displayable if equal to Displayable in parameter to commandAction. If it's equal then only process the command.

Case 2: commandAction calls are not serialized
You may use synchronization to serialize commandAction calls and then do whatever is written above in Case 1.
The commandAction gets called twice with the same Displayable.


Quote:
Originally Posted by grahamhughes View Post
Hmmmm... commandAction() should not be called again when it is already running.
That is not what I observed. commandAction is called, does what it has to, then gives control back to the system, then it is called again. (Not when it's already running, but twice in succession).

Quote:
Originally Posted by grahamhughes View Post
An important point you give is "if (the action) takes a long time"... it shouldn't. You must return from event handlers as quickly as possible. If something takes a long time to do, dispatch a Thread to handle it.
Yes, I know that, and I practice that. But here we're talking about 50 milliseconds, just constructing a simple screen. Creating a thread everytime I want to show a screen seems a bit exaggerated!

Quote:
Originally Posted by grahamhughes View Post
The Sony example you give is quite specific. It's not about key bounce, it's about event queuing.
Regarding multiple commandAction calls, I see on a Nokia 6131 the exact same behavior as the one described in the Sony post. I have a complete working demo sample similar to the sample code in one of my posts above and I am able to reproduce this every time.

My interpretation is that the key presses get queued, the setCurrent() does not make the new screen current right away, and the extra key press gets generates an extra call to commandAction. This is counter intuitive because once I called setCurrent I would expect my form to be gone and never receive anymore events.

But the doc for setCurrent actually does hint at this behavior in its first paragraph.
http://java.sun.com/javame/reference...i.Displayable)

I guess the only solution is what I do, i.e. guarding against double keypresses every time.
What puzzles me is that I seem to be the only one experiencing this. But users of my application certainly do call me about weird bugs, that I have traced back to this.

I'll post my sample if anyone's interested.
Reply With Quote

#13 Old Re: commandAction called twice - 2009-01-10, 16:23

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
OK. I have never seen this problem on any Series 40 before unless, as Arpit says, the user presses the key twice in rapid succession (which is hard to do in a 50ms window).

Can you reproduce this on more than one device? Is it possible that there is a fault on your device, dust in the contact, etc.?

What happens if you remove the Commands, or null the CommandListener on the current displayable, at the start of the commandAction event?
Reply With Quote

#14 Old Re: commandAction called twice - 2009-01-10, 17:19

Join Date: Jul 2007
Posts: 40
Location: Paris, France
olan75
Offline
Registered User
Quote:
Originally Posted by grahamhughes View Post
OK. I have never seen this problem on any Series 40 before unless, as Arpit says, the user presses the key twice in rapid succession (which is hard to do in a 50ms window).
It's harder to do when you're consciously trying, but my users do it inadvertently all the time, as shown by my app's execution logs. It looks like it's either a bouncy button or a bouncy finger...

Quote:
Originally Posted by grahamhughes View Post
Can you reproduce this on more than one device? Is it possible that there is a fault on your device, dust in the contact, etc.?
I only have one series 40 device at this time (a 6131). My customer has users with 6131 and 6212 and it certainly happens on several of those devices.

I doubt this is a fault. On my device I never experience the problem unless I'm trying to; I have to try hard hitting the keys twice very fast and then I get the problem. With a 50ms window I can do it sometimes, with 100ms I can do it every time.

It probably has to do with the way the users hit the keys. I tend to press firmly and then release and wait; maybe they do something else, go figure; in any case, the users are going to be the ones using the app so I have to make it work for them.

Quote:
Originally Posted by grahamhughes View Post
What happens if you remove the Commands, or null the CommandListener on the current displayable, at the start of the commandAction event?
Sure, nulling the CommandListener right at the start of commandAction completely cures the problem (that is what I was calling "guarding against double key presses" earlier). So I have to remember to do that every time I'm leaving a screen. A pain, but it works- too bad there's no event for a form closing.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
exe - destructor not being called nubiah General Symbian C++ 4 2007-07-27 11:25
ActiveObject RunL is called just once lskmao General Symbian C++ 3 2007-01-18 16:15
Errors building project in VS.2003 jensesaat General Symbian C++ 11 2006-11-13 17:54
HandleDatabaseEventL() of MContactDbObserver does not get called razas Symbian User Interface 1 2006-05-10 07:58
Application crashes when CEikAppUi::Exit() is called Leicester22 General Symbian C++ 2 2004-08-24 21:04

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia