10

I have an application with MVP architectural pattern. Now, I am trying to implement Livedata in my application. I searched a lot , but I can not found any tutorial or example for this. All tutorial says live data is for MVVM pattern.

Applying Livedata in MVP pattern is a correct method or not?

If anyone have idea about implementing Livedata in MVP please share.

Thanks in advance.

Ranjith KP
  • 858
  • 6
  • 18

1 Answers1

2

Lifecycle aware MVP is a good solution.

As you know Architecture Components introduce LiveData, a lifecycle-aware observable data holder class - the idea is great and sounds super handy. AC causes some "additional code to handle null case in our onChanged implementations" and also it's "harder to read and understand the flow" in the code.

Lifecycle aware MVP solve mentioned issues with these benefits:

  1. solve the lifecycle and configuration changes problems,
  2. clear and explicit View actions, like in classic MVP
  3. no LiveData and no Resource’s state handling in Activities or Fragments
  4. it’s easier to pass any necessary parameters straight to view methods (directly communicating with the view)

so if you have an existing MVP architecture and want to make use of ViewModels and their handling of configuration changes, this is an easy way to do achieve it

you can find more about it here.

majid ghafouri
  • 787
  • 2
  • 7
  • 23