Ok so i have an activity A that has a fragment A, and an Activity B that has a fragment B. Activity A is the main screen(like a login screen). Now in fragment B, i try to do some work and when there is a session expired, i send a message, logout and go back to the main screen A.
Now fragment B has an interface which it uses to communicate with the Activity B for other different functions. Should My Activity A implement this same interface of fragment B just for this logout session or is there a better way?
An illustration:
public class fragmentB extends Fragment {
public interface FragmentBProgressListener {
public void onShowDataDialog();
public void onRemoveData();
public void onSessionError(String errordata);
}
//or should i have another interface that implements this only in activity A
}
Activity B:
public class ActivityB extends Activity implements FragmentBProgressListener {
public void onShowDataDialog(){
}
public void onRemoveData(){
}
public void onSessionError(String errordata){
// finish Activity here
}
}
Activity A:
public class ActivityA extends Activity implements FragmentAListener, FragmentBFragmentBProgressListener {
public void onFragA(){
}
public void onShowDataDialog(){
}
public void onRemoveData(){
}
public void onSessionError(String errordata){
// show error dialog here from fragment B
}
}
is this a good way? any pitfalls i should be aware of?
You could always split the
onSessionError()method out into another interface.