I am trying to track an event (OnActivityResult
) from another class by creating an interface in the Activity and implementing that interface in that class. Like this:
OnAuthCompletedListener listener;
public void setOnAuthCompletedListener(OnAuthCompletedListener listener){
this.listener = listener;
}
public interface OnAuthCompletedListener {
void OnAuthCompleted(Auth auth)
}
and In Another class I wrote
MainActivity activity= new MainActivity();
activity.setOnAuthCompletedListener(auth->{
});
But whenever the event occurs the app crashes with a NPE. I understand I am using different activity instance that the real one. My question is how can I use that interface in a non activity class?
I also know that there is some better solution using RXJava, but I am not smart enough to implement that, can anyone help?