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 me exactly what final does and explain why you would nest a function in another like this?
private final Handler handler = new Handler() {
@Override
public void handleMessage(final Message msg) {
Log.v(Constants.LOGTAG, " " + ReviewList.CLASSTAG + " worker thread done, setup ReviewAdapter");
progressDialog.dismiss();
if ((reviews == null) || (reviews.size() == 0)) {
empty.setText("No Data");
} else {
reviewAdapter = new ReviewAdapter(ReviewList.this, reviews);
setListAdapter(reviewAdapter);
}
}
};
This is an Anonymous Class.
What is actually happening is that a
subclass of
Handleris beingcreated with an overridden
handleMessagefunction.You also asked “Could somebody
explain to me exactly what
finaldoes”. A nice explanation can be
found here.
In the case of your example the
finalkeyword stops anybody from being able to assign a new instance / null the instance of the variable “handler” meaning I cannot write the linehandler =ornull;
handler = new Handler() {after your example code snippet.... }