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 IUpdateHandler to which you have no reference. Instead you should firstly store created IUpdateHandler in some variable e.g IUpdateHandler myHandler = new IUpdateHandler() {...}); and then register it using this.registerUpdateHandler(myHandler). Having reference to handler you can unregister it using method you mentioned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With