4

アプリケーションをGoogle Play ServicesおよびMortarと統合して、ユーザーの現在の場所を取得しようとしています.

https://developer.android.com/training/location/retrieve-current.html#CheckServices

これには、Google Play Services が利用できない場合に onActivityResult() を処理する必要があります。

これを行う方法に関する私の最初の本能はgetFirstScreen()Main.java見返りに空白のロード画面を作成することです. https://github.com/square/mortar/blob/master/mortar-sample/src/main/java/com/example/mortar/core/Main.java

注入後、onCreate()Google Play Services が利用可能かどうかを確認します。そうである場合は を呼び出しflow.goTo(<location using screen>)、そうでない場合は何もせずonActivityResult()に呼び出されるのを待ちます。次に、 が起動しonActivityResult()たら、単に を呼び出しますflow.goTo(<location using screen>)

上記は私には少しハックに思えます。(説明が必要な場合はお知らせください)。したがって、他の解決策は、アクティビティのライフサイクルに接続されたサードパーティのライブラリを使用して、この Mortar + Flow とonActivityResult()同様のことを行い、プレゼンターに接続することであると考えています。これの問題は、プレゼンターから にアクセスできず、が必要Activityなため呼び出すことができないことです。GooglePlayServicesUtil.getErrorDialog(...)Activity

onActivityResult()はとても重要だと思います。おそらく、それは Mortar ライブラリの一部であるべきでしょうか?

4

1 に答える 1

9

Square Register で一般的に startActivityForResult を処理する方法は次のとおりです。

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.
  }
}

アクティビティは次のようになります。

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();
  }
}

それはエラーダイアログの助けにはなりませんが、とにかく私にとっては別の懸念のように思えます. そこに Popup / PopupPresenter ペアを使用できるようです。(私は Popup に興奮していませんが、より良いアイデアが得られるまで仕事を終わらせてくれます。) それとも、アクティビティ自体を先に進めて、それ自体に対処する必要があるのでしょうか? 私は Play Services にあまり詳しくなく、まだ扱ったことがありません。

于 2014-09-22T19:10:57.390 に答える