retrofit v/s async task for one request [closed] - android

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 6 years ago.
Improve this question
I am already aware of the advantanges of retrofit and have used it in many scenerios. For a particular application , I need to call only 1 login API which will do authentication.
I am not sure if the advantages of retrofit are worth it for only one API. or is it a overhead and I should Http for sake of simplicity

If it is just a single request, then I'd say go with the simplest/lightest approach. But these things tend to evolve with time, therefore you are likely to find yourself in a position of adding another one, then another one...
Remember - networking mechanism is not an architectural decision. In fact, your application should not care what networking mechanism is being used - it should depend on a general interface that you define. You could start with implementing this interface using the simplest approach, and add a more complex implementation in case your networking requirements evolve. You could also implement several approaches and benchmark them...
So, whatever approach you choose, I recommend not to "pollute" your business logic with networking logic, but hide it behind interface. This way even if you make the wrong decision now, it will be a matter of few hours to fix it later.

For a single API call http is fine. As you know using library with your application is going to occupy user phone space when they install your application on their device. so for a single call, you are good to go with async task.

Related

Where should backend API be called - in use case or in repository? [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 2 years ago.
Improve this question
We are doing architecture for our new android application that requires offline mode also and have a dilemma about one detail.
General recommended architecture is shown in this picture:
Now, this makes pressure on repository doing 2 things: communication with API and SQLite which can easily get very complicated + harder to test.
At the same time, we have Use Case in between ViewModel and Repository to orchestrate jobs done across multiple things: services, multiple repositories, etc...
The question is:
Should backend API be called from Repository or maybe better to do it in Use Case? And why?
IMO neither. Generally I prefer this kind of architecture layering:
RemoteSource - Communicates with your networking or bluetooth API. It essentially wraps the retrofit interfaces, and does mapping & thread switching to IO
LocalSource - Communicates with your DB api (Room, SqlDelight). Also mapping & thread switching
Repository - Handles the logistics, whether something should be fetched, cached, etc...
UseCase - Combines multiple type of entity operations between repositories
So TL;DR: you can create a RemoteSource abstraction over your Retrofit interfaces

Is it necessary to use MVVM pattern or architecture components in android for beginners in android? [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 4 years ago.
Improve this question
I am new to android. I have already built 80% of my app without following a MVVM pattern or using android architecture components such as View Model, Livedata etc because most of the tutorials didn't follow these patterns. My code just has data models and business logic, data binding on the activity, fragments itself.
Just got confused about the fact that whether is it okay to launch an app in the old school style or I should rework with some architecture pattern?
Its ok to use any pattern you think is best for your app. There are no requirements, technical or policy wise, about how you implement your code. If you feel MVVM is right use it. If you don't, avoid it. Even Google wouldn't claim its the best for every usecase, its just another tool in the box.
Architecture components solve a bunch of complex problems. Among these are:
Code maintainability
App performance
Consistent behavior across devices and versions of Android
That last one is key in my opinion. Rolling your own architecture can lead to bugs as your app gets exposed to more and more devices after release. Devices that you just didn't see during testing.
I would not hold up your app's launch to integrate architecture components, but certainly you should consider refactoring your app where it makes sense as you update it for future releases.

Should I use Google Volley instead of AsyncTask [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 6 years ago.
Improve this question
I did some research on Google Volley and found that it is somewhat easy and clean to use.
But I am still not sure as to what the advantages of using it are and whether I should still use the AsyncTask.
I know AsyncTask works as a background task and that it is separate but what about Volley?
Which one should I opt for?
This is mainly an opinion based question that is largely dependent on the needs of your particular application. Volley provides a lot of things for you out of the box, like network caching (assuming you're given correct cache headers from your server), and an easy to use API with all of your callbacks and different threading layers handled for you. So, it really depends on what you're looking. Personally, I think any production worthy application should use some sort of networking library that a team has spent plenty of time patching and prepping for you (rather than trying to reinvent the wheel), and since a Google team has gone through the trouble for doing this for you...why not?
One cannot compare Volley with an AsyncTask.
So your question makes no sense.

which is better retrofit or volley? [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 7 years ago.
The community reviewed whether to reopen this question 8 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
I am trying to implement a code which makes intial get/post request to fetch the data then using that data i m going to fetch download links with jsoup.
file are n't greater than 200 kbs
so which is better to do this task?
1)intial request
2)downloading files
How to chose between: Volley and Retrofit
If you are :
Making Requests then I would like to say though both frameworks are capable of the same outcome, Retrofit is capable of accomplishing this without customization. However, if you are implementing multiple requests within your application, and I suspect you are, customization may be necessary within Retrofit. Though that could be the case, at the simplest level Retrofit has the easier solution.
Downloading Files(Image): Being able to make file requests was a pretty large factor in the making of our decision. Volley comes packaged with a loader specifically designed to download images for you. Packaged along with the loader is a custom view called the NetworkImageView in which the developer only has to hand a URL and an ImageLoader to and Volley does the rest. This view is specifically targeted to work well with list views and allow for automatic cancellation of requests when the images parent view is destroyed. On the contrary, Retrofit does not easily support image downloads. To accomplish what we are able to with Volley, one would be required to download and include another library in your project such as Picasso. So here Volley is a better solution.

Client development approach when webservices are not finished yet [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 8 years ago.
Improve this question
I'm developing an Android application which consumes REST services that are not finished yet. I´ve been looking for some tool that could mock this REST services, in order to don't get stucked, and I found SoapUI. I'm having problems to setup this tool and make the REST services visibles for my mobile device.
My question is if I´m following the right approach or there are other choices that could fit better.
I don't have any experience with SoapUI, but I thought it only made Soap calls, not mock them. But maybe I'm wrong?
Either way, I would recommend doing the following for mocking your REST service that isn't finished:
Make an interface that represents the REST service. In Java you'd have something like DataService.java as the interface and then you can create various implementations of it. Things like DataServiceRestImpl.java - which would be the live REST service once it's done.
Afer you've made the interface, go ahead and make a mocked version of it. DataServiceMockImpl.java. This way you can pass around the interface in your code and the implementation can change easily.
Once the real service is ready you just swap the implementation of the interface and everything still works fine.
(As a note, this will also help you do unit testing!)

Categories

Resources