How to handle onActivityResult() with Mortar

南楼画角 提交于 2019-12-04 09:24:30
rjrjr

Here's how we generally deal with startActivityForResult in Square Register.

public SomePresenter extends Presenter<SomePresenter.Activity> {
  public interface Activity {
    void startActivityForResult(android.content.Intent intent, int requestCode);
  }

  public final void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Make sure it's the expected requestCode and resultCode and do your thing.
    // If it isn't, no-op, someone else will handle it.
  }
}

And the activity looks something like:

public MyActivity extends Activity implements SomePresenter.Activity {


  @Override protected void onCreate(Bundle bundle) {
    // Do the usual mortar init stuff

    somePresenter.takeView(this);
  }

  @Override protected void onActivityResult(int requestCode, int   resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    somePresenter.onActivityResult(requestCode, resultCode, data);
  }

  @Override protected void onDestroy() {
    somePresenter.dropView(this);
    super.onDestroy();
  }
}

That doesn't help you with the error dialog, but that sounds like a separate concern to me anyway. Seems like you can use a Popup / PopupPresenter pair there. (I'm not thrilled with Popup, but it gets the job done until we have a better idea.) Or maybe the activity should just go ahead and deal with it itself? I'm not super familiar with the Play Services, haven't dealt with them yet.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!