S
S
Sergey Vodakov2016-08-18 12:09:16
Java
Sergey Vodakov, 2016-08-18 12:09:16

Android. How to choose the right architecture for an application with http requests?

I am writing an application that receives xml from a Web service and displays its contents in a ListView. Since both java in general and Android in particular are new things for me, I have to process mountains of information, often outdated. I am also very familiar with design patterns. Now everything works for me, but I'm not sure that I'm doing everything right. Please point out what is wrong with my solution and what design patterns I used.
My application consists of Application, Activity and Service. I read about how bad it is to use AsyncTask and therefore decided to use Services.
Application in onCreate creates a ServiceHelper and provides access to it. An interface is connected to the Activity, a listener for the response from the service. When a button is pressed in an Activity, the ServiceHelper creates an intent and starts the service. The service, after completion of work, sends the result of work through the ServiceCallbackListener interface in the bundle.
Activity on the onServiceCallback event reads the result from the bundle.
Then I realized that in the case when the Callback from the service comes to a stopped application, the result disappears into nowhere.
To solve this problem, I made it so that the service saves the bundle with the result of the work in the ServiceHelper, and the Activity, after processing the callback, tells the helper that the cache can be cleared. Now I have an Activity, on the onPostResume event asks the ServiceHelper if the service is still processing a request with the specified id, if not, is there data for this id, and if so, loads them into the ListView and tells the helper that the data with this id need to be removed.
Everything is fine, but this implementation is inspired by an article that is already five years old. I heard that now in Android they use Loaders, retrofit, rxJava, and many other scary words, hence the doubts arose, am I cycling where ready-made objects should be used?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2016-08-18
@evgstrannik

My advice is don't chase "hipster" new trends. If the mechanism works, works well and covers all your needs, then everything is ok. This generally applies to AsyncTasks as well.
I personally managed with the standard AsyncTask, and stored the result cache as json on the file system. It may not be super modern, but it works, it works quickly and transparently.

O
Oleg Gamega, 2016-08-18
@gadfi

on the one hand, I agree with Eugene , if android is not your main specialization and the project does not need to be expanded, then don’t worry, if you want to make android your main specialty, then yes, you are building big ones that no one needs today,
in which case you will have to figure it out with all these terrible words, apparently you are familiar with Google, so I won’t duplicate them for you, I’ll just remind you
read, try, but do not implement more than one new technology at a time, try to follow the principles of SOLID and even without lacy architecture, your application will work quite cheerfully. If you don’t know how to do it well, do it head-on, just remember common sense.
new technologies, elegant architectural solutions will come with experience.
Read more, see someone else's code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question