I am writing an application that receives xml from a Web service and outputs its contents to a ListView. Since java in general and Android in particular are new things for me, I have to recycle mountains of information, often outdated. I'm also very superficially familiar with design patterns. Now everything works for me, but I am not sure that I am doing everything correctly. Please indicate 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. After completion of the work, the service sends the result of the 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 a Callback from a service comes to a stopped application, the result disappears into nowhere.
To solve this problem, I made it so that the service saves a 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, it asks the ServiceHelper if the service is still processing a request with the specified id, if not, is there any data id for this, and if there is, loads it into the ListView and informs the helper that the data with this id need to be removed.
Everything is fine, but this implementation is inspired by the article https://habrahabr.ru/post/144275/ , which is already five years old. I heard that now in Android they use Loaders, retrofit, rxJava, and many other scary words, hence doubts arose whether I am a city of bicycles where it is necessary to use ready-made objects?
Service makes sense to use only if the exchange of information is ongoing, including when the application is turned off, if only at the moment when the application works much better, it is easier and easier to restrict ourselves to the usual
ListView obsolete thing already, if you do not write for Android 2.3, then the
RecyclerView used. Everything is the same, it works faster, the
ViewHolder in the box and there are more features.
Retrofit a great thing, but if you don't use a full-fledged good REST API, and instead just populate the data with a regular post, then it's better to limit
OkHttp to the
OkHttp library. If you need to convert large data by objects from
JSON there is a
GSON library to simplify the process, which is also not always needed.
In my opinion, there is no need to store data in bundles. Can be passed directly from stream / service to fragment / activity.