Mistery of Lookup.Result

Leave a comment

February 14, 2012 by huionn

I encountered a weird problem that method resultChanged(LookupEvent) of my LookupListener is not fired.

Tried many way but could figure out the reason.

Then I look into the javadoc of Lookup.Result and read this:

 Sometimes people report that their listener is not receiving
 events (for example IZ 191471)
 or that the listener receives few events, but then it stops
 listening.
 Such behavior is often caused by not keeping strong reference to
 the {@link Result} object. When it gets garbage collected
 it can no longer deliver events. Thus remember to keep reference
 to the object you are attaching listener to.

Keeping strong reference to Result instance solves my problem : )

(one way to keep strong reference is using static variable in class)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: