Moxy MVP application architecture. Presenter should receive longitude and width data from the model and give it to View. I can not figure out how to implement a model based on GoogleApiClient, since it requires context and which class should implement GoogleApiClient Callbacks?

    1 answer 1

    1. It is worth using Context Application. It can be delivered in two ways:

      • Inject using dagger or something else
      • Make the LocationPresenter.init(Context context) method LocationPresenter.init(Context context) , in which you save the context in the local field LocationPresenter . Just make sure that you set the application context, not activation! Otherwise there will be a memory leak. To do this, inside the LocationPresenter , you can save the link not to the context that came, but to context.getApplicationContext() .
    2. As a GoogleApiClient Callbacks, I would make a LocationPresenter myself. And when changing the location, I would send new data in the view.

    3. If you need your location to be tracked on several application screens at once, you can make this weak weak presenter and use it where you need it. When all activities that use this presetner are stopped, it will be destroyed.

    4. Unsubscribe from GoogleApiClient is required in the LocationPresetner.onDestroy() method.