OK, I have a login class like the snippet below
public class LoginClass {
public void login() {
login.authorize(username,password);
//run activity specific code here
}
}
This class is quite generic, but depending on which activity calls LoginClass.login(), I would like different actions to be performed.
I’ve seen some implementation where a function is passed into the class and this function is then run on completion. Can anyone give me a brief example on how to do this.
Functions are not first class objects in Java as seen on Android – you cannot pass a function. The ideology of Java calls for deriving from your generic class (possibly anonymously) when it needs to be specialized. Like this:
Alternatively, you can create hooks in the login class – functions that are called whenever custom action is needed – and override those in the activity. Such is the Java way.