GENERIC-14: Have special care in designing background tasks, especially by considering the apps’ lifecycle.


Description

Each app runs on the main thread. Performing long computation tasks on the main thread could slow down the app. And lead to an unpleasant user experience. So whenever we perform a task like a network request, we perform then as a background task. It is important to handle your background tasks correctly. For example we do not want the user to wait forever when a network error occurred.

Example

We created a simple MVP login Application. Our ViewUserPresenter asks the ViewUserInteractor to show the Users with the mViewUserInteractor.showUsers(this); method. Which takes as parameter the ViewUserPresenter.

Either the ViewUserInteractor will get all the users, or there will be an exception. Either way, the ViewUserPresenter needs to know that the process has finished. Otherwise the User will not know if something has happened or not.

It is important that our background-tasks do not run forever and that the user knows that this task has finished.

Check out the Github page to view the complete repository.