My apologies if this question is a bit newbie-ish. I’m using AndEngine and my question is specific to that framework. Suppose I create an IUpdateHandler as follows:
this.registerUpdateHandler(new IUpdateHandler() {
@Override
public void onUpdate(float pSecondsElapsed) {
doUpdate(pSecondsElapsed);
}
@Override
public void reset() {
// TODO Auto-generated method stub
}
});
In my doUpdate() method I have the information I need at some point to determine that it’s time to unregister the IUpdateHandler. There’s a method, unRegisterUpdateHandler(), which sounds perfect for this purpose, but in order to use it I need to pass in some reference to the updatehandler, and I have no such reference. What am I missing?
Code you provided creates anonymous instance of
IUpdateHandlerto which you have no reference. Instead you should firstly store createdIUpdateHandlerin some variable e.gIUpdateHandler myHandler = new IUpdateHandler() {...});and then register it usingthis.registerUpdateHandler(myHandler). Having reference to handler you can unregister it using method you mentioned.