My question is how best to work for the organization of the methods, I will present 2 implementation options that I am in doubt, whenever I have in Fragment a reference through getActivity () should I use interface? :
1st choice: I'm declaring directly in Fragment the getActivity () :
Toast.makeText(getActivity(), "mensagem", Toast.LENGTH_LONG).show();
2nd option: I created an interface with the method:
public void mensagemToast();
Then in Activity I implemented this method using this (Activity) now:
@Override
public void mensagemToast() {
Toast.makeText(this, "mensagem", Toast.LENGTH_LONG).show();
}
Then I created a listener in Fragment to call this method that is implemented in Activity:
listener.mensagemToast();
This is just an example I have several cases similar to this that in Fragment I directly call the getActivity () . What is the best way out of the options I presented?
1st that seems to be over simple but, are you taking a direct reference to Activity?
2nd that is more bureaucratic but unbound (separate) from Fragment?
Or is there another solution that be better than the ones above?