在看ForegroundService的时候,下面这段
private static final Class[] mStartForegroundSignature = new Class[] {int.class, Notification.class};
mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature);
实际上是利用了JAVA反射机制 (使用场景:http://stackoverflow.com/questions/3331392/is-it-reflection-when-i-use-getclass-getmethod)
获取时,mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature); ==>
mStartForeground = this.getClass().getMethod("startForeground", mStartForegroundSignature); ==>
mStartForeground = serviceObject.getClass().getMethod("startForeground", mStartForegroundSignature);
|| ||
method name method parameter type
when call:mStartForeground.invoke(this, mStartForegroundArgs);