Activity or Fragment as View on MVP [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to know which is the better implementation of the view on MVP.
For example in small Apps, It's better to use one or two activity's and use as a View the Fragments? or It's better use one Activity for all screens as View without any Fragments?

Whether you should use activity or fragment not actually depends on MVP. This decision should be taken based on your app's requirement. If the app is such that the pages do not have much to share between them and pages are quite unique based design and functionality, you should go for activity. On the other hand, if there are lots of interactions going on between the pages or based on design and functionality lots of similarity is found between the pages, using fragments will be a better option. It will reduce lot of duplicate codes.

One definition of MVP (there are quite a lot) states, that the presenter is an implementation detail of the View. So, MVP per se has no preference for either of Activity or Fragment. You can attach a presenter to both of them equally well and use it to separate business logic from the presentation layer.

Related

How to properly implement Multi-threading in a JavaFX MVMM application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm looking for a way to thread the ViewModels in a MVVM Architecture, without having to use tasks everywhere.
My ideal solution would be :
1 Application Thread (with the view)
1 Background Thread (with the viewModel)
Message passing between the 2
ViewModels still behave as normal Java Classes w/o Tasks/Service/Platform.runlater in every method
Is there a way to do this without bloating the code ?
This is probably not going to work the way you would like it to work. The view-models normally communicate with the views via bound properties. Therefore the properties of the view-models must always be updated on the application thread.
The proposed JavaFX way of dealing with concurrent background activities is to use Services. But if you don't like that it maybe worth it to have a look here: https://github.com/ReactiveX/RxJavaFX

How can i keep variables state across all activities? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
How can i presist data across all my activities so when I change a variable on activity A, that variable will be changed on all activities to which it belongs.
So to play safe and easier I would like to know the right way to acomplish this.
I read some ppl sayng to use static variable but I have like 45-70 variables and 21 classes and doenst feels right to me to just put everything static...
I have also been using intents to pass the data between activities but I have to update it manually all the time wich can lead to inconsistencies sometimes.
My goal is to have a class that can be shared between all activities automatically and replicate any changes across all activities.
What you're looking for here is a model object. Android has a ViewModel object that would work well for this. The ViewModel object should be able to outlive the lifecycle of any activities or fragments that use it. I would recommend checking out that link as it will likely explain how to use a ViewModel more thoroughly than I ever could.
Edit: I misunderstood some parts of your question. Using a static class like you mentioned is definitely an option (and in my opinion, not an anti-pattern). If you would like to persist that data across app restarts, you could also utilize Room.
On a side note, I would also recommend using LiveData inside your model. LiveData is a wrapper of sorts that makes practically any object observable. You'll be able to observe your data in your model object and notify activities that need to know accordingly.

Where should I perform Retrofit operations? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm new to MVP, Retrofit and Dagger, so I've decided to make a simple app based on Riot Games API, that just shows some game's info in a list. Everything works fine, but it made me wonder: "Is presenter a good place to do such things, like Retrofit operations? I couldn't find anything about it. There are some simple examples how to use Retrofit, but they are sometimes shown even inside an activity class, which doesn't seem right to me.
So, here is my question: Where should I perform such operations to make the code as clean as possible?
My app repository: https://github.com/Mallorax/Rito_Api_Test
If the Model is what Retrofit returns, you can't put the call there.
The View is intended to separated from the Presenter, and subscribes via Callback interfaces, which Retrofit provides out of the box.
Therefore, your only option without involving some Service layer is to put Retrofit in the Presenter.
I suggest you to place some network call to plain class e.g. Interactors for example LoginInteractor which contains loginMethod, than when it finishes pass the result to the presenter class, which will handle the data and will convert (or not) it for some kind of model which is ready to be presented on UI.
Activity/fragment contains Presenter and Presenter contains Interactor(s)

Making the user follow specific steps [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Am not sure if the title describes what I want. Am developing an App on Android where kids start a new empty drawing project and finish with a full drawing at the end by dragging different shapes from a list of shapes that I created for the App. My problem is that I dont know how am going to follow the kid steps.
The kid is supposed to read a message in each step and try to apply it and then click on a next button to view the next step.
I want to make sure that he do exactly what the message is saying in order to view the next step.
Theoretically, how is this applied in Java ? If for example, there would be 20 steps how can I make the app follow up with him and make sure he is doing the right thing
You are looking to create a wizard. In Java use a MVC libray Spring-MVC or if its android you can use similar approach. Basically you want steps and views while saving the state - typical MVC pattern. Have a model object that is passed along to the views. Each view will have portions of the model that it can read/write to.
Android -refer to WizarDroid.
Spring - AbstractWizardFormController will help

Best design practice with using methods that multiple fragments use [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am developing an Android unit conversion and calculator application in which I have a 3 fragment ViewPager set up and was wondering what would be the best OOP design practice when attempting to use methods over many fragments. Should I set up a centralized calculate method and call it within each fragment?
I currently have each fragment isolated with their calculations, spinner values, and intermediary values. I am also sending a result of a calculation from a fragment back to another fragment through an intent on the Main Activity.
My code currently works, but as I am learning more Java I would like to start piecing together best design practices and efficient code. Thanks for any insight!
If possible, i'd write something like CalculationUtils.java and define every common method inside, as public static, and later call them with CalculationUtils.method1(...)

Categories