Como é possível transmitir uma atividade do Android para uma interface?
Na documentação do Android aqui:http://developer.android.com/guide/components/fragments.html Um fragmento implementa uma interface.
No retorno de chamada onAttach (), parece lançar a atividade atual em uma interface. Conceitualmente, como isso é possível e é o mesmo tipo de prática padrão no Java?
public static class FragmentA extends ListFragment {
// Container Activity must implement this interface
public interface OnArticleSelectedListener {
public void onArticleSelected(Uri articleUri);
OnArticleSelectedListener mListener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnArticleSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnArticleSelectedListener");
}
}
...
}