Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

In blackberry we can override keyChar() method and capture the keypress event or we can register onKeyPressListener. i know, onKeyListener is observer pattern.

In android also there is a KeyEvent.callback and onKeyListener

Both are events why we no need to register for keyChar event. what is the difference between both pattern?

share|improve this question

2 Answers 2

up vote 14 down vote accepted

Callback. The other code tells the developer: Hey, if this event occurs, I'll call the function in this bucket. You must know where the bucket is to connect your callback.

Listeners. The other code tells the developer: Hey, if this thing occurs, I'll send this event. You can connect your handler (hopefully) where it makes sense to you.

share|improve this answer
which one should i accept as answer? you and ammoQ both are right. Its a split pot. –  Vivart Jun 17 '11 at 12:43
@Vivart - Easy, accept Andrea's, it provides more detail and ammoQ doesn't really need more rep. *8') –  Mark Booth Jun 17 '11 at 14:38

There can be many listeners for some type of event, but only one callback.

share|improve this answer
In android we can set only one OnClickListener to a view. –  Vivart Jun 17 '11 at 8:28
It's quite possible that their definition of "listener" doesn't match that of other products. Usualy, you don't have a "setFooBarListener()" method, but an "addFooBarListener()" method. –  user281377 Jun 17 '11 at 8:31
Another distinction could be that callback means a function (or closure or delegate), while listener is an object of a class that implements the corresponding Listener interface. –  user281377 Jun 17 '11 at 8:42
Thanks @ammoQ and sorry i can accept only one answer. –  Vivart Jun 17 '11 at 16:17
Vivart: doesn't matter, my answer isn't that good anyway –  user281377 Jun 17 '11 at 17:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.