I read the official Android documentation on creating an interface to be able to communicate between a parent activity and a fragment. So I did but my app crashes when I call one of the methods to get a value from the parent activity.
if have an interface like this in my fragment
public interface InteractWithFragmentA {
String getStringText();
}
In my calling activity I tested it out with a dummy text
@Override
public String getStringText(){ return "Some dummy text";}
I have a variable in FragmentA.java that's a reference to the host activity and casted to InteractWithFragmentA, but when I call the method using
_hostActivity.getStringText()
the app crashes. Is there something that I'm missing? I've seen some suggested methods for getting the host activity's variables by making them public and static or some other method but I'm trying not to couple the fragment to that activity. Thanks in advance.