Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handler in Android

I'm implementing IPC via Handlers in an Android application. In the official documentation (here http://developer.android.com/reference/android/app/Service.html) there's an example:

class IncomingHandler extends Handler {
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case MSG_REGISTER_CLIENT:
                mClients.add(msg.replyTo);
                break;
            case MSG_UNREGISTER_CLIENT:
                mClients.remove(msg.replyTo);
                break;
            case MSG_SET_VALUE:
                mValue = msg.arg1;
                for (int i=mClients.size()-1; i>=0; i--) {
                    try {
                        mClients.get(i).send(Message.obtain(null,
                                MSG_SET_VALUE, mValue, 0));
                    } catch (RemoteException e) {
                        // The client is dead.  Remove it from the list;
                        // we are going through the list from back to front
                        // so this is safe to do inside the loop.
                        mClients.remove(i);
                    }
                }
                break;
            default:
                super.handleMessage(msg);
        }
    }
}

My question is simple: what does this line do?:

super.handleMessage(msg);

Am I obliged to call that method?


EDIT: I know that this will call the parent's implementation of that method. But what's in that method? Is there something special that have to be done prior the release of the message?

Thanks in advance

like image 412
mneri Avatar asked Sep 24 '26 07:09

mneri


1 Answers

A quick glance at the source code shows that the super class implementation of this method does nothing. I would call it nonetheless because a future version of Android might behave differently.

like image 96
devconsole Avatar answered Sep 25 '26 21:09

devconsole



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!