S
S
Stepan2021-03-30 22:48:50
Android
Stepan, 2021-03-30 22:48:50

Is this normal application logic?

I am making an application that will check for availability and display a fresh photo from one of the photo hosting sites. I threw in the following work logic:
When starting the application, we check whether WorkManager is installed:
- if WorkManager is installed, cancel it and start AsyncTask,
- if WorkManager is not installed, immediately start AsyncTask.

When closing Activity:
- end AsyncTask and start WorkManager.

AsyncTask (with an interval of several minutes):
- if there is no Internet, displays the Snackbar with a message, shows the last uploaded photo (if there was, otherwise - a “stub”).
- if the Internet is available, it checks for new photos and changes the photo in the activity, saves the last uploaded photo and does not show Notifications.

WorkManager (will start when there is internet):
- checks for new photos with the minimum possible interval (15 minutes),
- if a photo has appeared, displays a Notification from which you can open Activity with this photo,
- saves the last uploaded photo.

Does it make sense to use Service instead of AsyncTask (as it is deprecated)?
What else I did not take into account in the logic of work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-03-31
@zagayevskiy

This simple app will load your smartphone like hell. And eat the battery. The right way is push. Make your own web service that will monitor photos and send push notifications to the application.
Asynctask does not need to be used at all. For nothing. Retrofit/OkHttp is enough, and Handler.postDelayed.
The service does not need to be used, you can consider it deprecated too.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question