Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndEngine confusion unregistering an IUpdateHandler

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?

like image 712
Cameron Fredman Avatar asked Dec 09 '25 20:12

Cameron Fredman


1 Answers

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.

like image 60
Damian Jeżewski Avatar answered Dec 12 '25 16:12

Damian Jeżewski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!