I\'m just starting out on android and my java is verry rusty. I can\'t remember ever seeing a function nested in another function like this before. Could somebody explain to
This is an Anonymous Class.
What is actually happening is that a
subclass of Handler is being
created with an overridden
handleMessage function.
One of the most elegant things about anonymous classes is that they allow you to define a one-shot class exactly where it is needed. In addition, anonymous classes have a succinct syntax that reduces clutter in your code.
You also asked "Could somebody
explain to me exactly what final
does". A nice explanation can be
found here.
In the case of your example the final keyword stops anybody from being able to assign a new instance / null the instance of the variable "handler" meaning I cannot write the line handler =
null; or handler = new Handler() {
... } after your example code snippet.