[Android] Anonymous Inner classes
Something that is used very often in Android programming, are the Java constructs, anonymous inner classes. They are used to create things like onClickListeners and start new intents.
Inner classes are basically classes that are embedded within another class. Just like top-level classes, inner classes can have methods and their own variables.Â
A couple of tricky things about these inner classes:
- They can only call member variables of the outer class directly if those instance variables are of type "final" i.e., the instance variables are immutable. This is because the instance variables and the inner classes will likely be compiled at different times. The outer class instance variable may be complied at run time, but the inner class may only be called once used
- If you want to call an outer-class non-final instance variable from an inner class, you can use the convention:
OuterClassName.this.instanceVariableName










