さて、フラグメントAを持つアクティビティAとフラグメントBを持つアクティビティBがあります。アクティビティAはメイン画面です(ログイン画面のように)。フラグメントBで、いくつかの作業を試み、セッションの有効期限が切れたら、メッセージを送信してログアウトし、メイン画面Aに戻ります。
これで、フラグメントBには、他のさまざまな機能のためにアクティビティBと通信するために使用するインターフェイスがあります。私のアクティビティAは、このログアウトセッションのためだけに、フラグメントBと同じインターフェイスを実装する必要がありますか、それともより良い方法がありますか?
イラスト:
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
}
アクティビティB:
public class ActivityB extends Activity implements FragmentBProgressListener {
public void onShowDataDialog(){
}
public void onRemoveData(){
}
public void onSessionError(String errordata){
// finish Activity here
}
}
アクティビティ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
}
}
これは良い方法ですか?知っておくべき落とし穴はありますか?