我将使用Handler在Android应用程序中实现IPC。
在官方文档(此处http://developer.android.com/reference/android/app/Service.html)中有一个示例:
我的问题很简单:这行代码是做什么用的?
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);
}
}
}
我的问题很简单:这行代码是做什么用的?
super.handleMessage(msg);
我需要调用这个方法吗?
编辑: 我知道这将调用父类中该方法的实现。但是这个方法里面有什么特殊的内容吗?在发布消息之前是否需要进行某些特殊处理?
提前感谢。