Suppose for example you wanted to give the activity a String and have it return a Integer:
public interface MyStringListener{
public Integer computeSomething(String myString);
}
This can be defined in the fragment or a separate file.
Then you would have your activity implement the interface.
public class MyActivity extends FragmentActivity implements MyStringListener{
@Override
public Integer computeSomething(String myString){
/** Do something with the string and return your Integer instead of 0 **/
return 0;
}
}
Then in your fragment you would have a MyStringListener variable and you would set the listener in fragment onAttach(Activity activity) method.
public class MyFragment {
private MyStringListener listener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
listener = (MyStringListener) activity;
} catch (ClassCastException castException) {
/** The activity does not implement the listener. */
}
}
}