warp MVP presenter inside viewmodel in android?

Multi tool use
Multi tool use


warp MVP presenter inside viewmodel in android?



one of mvp presenter pattern disadvantages is handling activity state or orientation change , while viewmodel survive orientation changes , so can i wrap presenter inside a viewmodel and still using MVP ?




2 Answers
2



You can, of course, have a presenter that lives inside a ViewModel to survive configuration changes, and live for the same time as the Activity or Fragment does.


ViewModel


Activity


Fragment



You could also make your presenter itself the ViewModel subclass, or even use MVVM with the view component observing LiveData from the ViewModel, to be automatically safe with lifecycle handling at that point (as seen being pushed by Google recently).


ViewModel


MVVM


LiveData


ViewModel





thank u so much
– Mahmoud Assaf
Jul 2 at 19:56



Actually, MVP MVVM and MVC are all just design patterns.
None of them inherently solve problems imposed by a particular platform.
They aim to provide a mechanism for developers to organize the structure of code into logical roles under the segregation of responsibility principle (see SOLID software engineering).



The problem of state preservation in relation to configuration changes in Android Activities (Rotation is just one of these) is present as a feature of the Android operating system.
Google has built-in one solution to their Architectural components, which I presume you are referring to as ViewModel but that doesn't mean MVVM as a pattern supports it directly.


ViewModel



As mentioned by @zsmb13 , you can fairly cleanly use the viewmodel as a presenter.



As far as state preservation goes though, I have another approach here: ucs Framework and a little article about one of the approaches here: A Simple MVP approach for Android - The Simple MVP approach is now deprecated in favor of the ucs framework which in addition to state preservation also manages threading.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

7m,48qsnfiJWSGAM4fNGYU83lJVL6H744qz5dZ2VC bVDj,DB t
Chi,Vcnl CP Qva1LdyxaA RFmNNQ1lDPOF0bEA9sl5x2V2FVp3EtWz2UClH3msf2ercbrkBfkw5UY

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications