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
It is worth using
ContextApplication. It can be delivered in two ways:- Inject using dagger or something else
- Make the
LocationPresenter.init(Context context)methodLocationPresenter.init(Context context), in which you save thecontextin the local fieldLocationPresenter. Just make sure that you set the application context, not activation! Otherwise there will be a memory leak. To do this, inside theLocationPresenter, you can save the link not to thecontextthat came, but tocontext.getApplicationContext().
As a GoogleApiClient Callbacks, I would make a
LocationPresentermyself. And when changing the location, I would send new data in the view.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.
Unsubscribe from GoogleApiClient is required in the
LocationPresetner.onDestroy()method.
|