Interlude: So, What’s Wrong?

We’re done! Right?

Right?!?

.

.

.

Well, OK, we are not done.

There are some features that we could add, such as filtering the list of items based on whether they are completed or not, or being able to save the items out to a Web page.

However, beyond that, there are some fairly fundamental flaws in our app implementation, and some corresponding features of the Jetpack components that can help us address those.

Issues With What We Have

The app has few, if any, outright bugs. However, it does have some shortcomings that affect users, ourselves, and (theoretical) future maintainers of the code.

Lack of Persistence

The biggest gap is that our to-do items are not stored anywhere other than memory. As soon as our process is terminated, the to-do items will go away. And our app’s process may not live that long in the background. So, after a period of time, it is all but guaranteed that the user will have no more to-do items.

Admittedly, some users will consider that to be a feature, not a bug.

However, in general, people put items in a to-do list in order to keep track of what needs to be done, and for that, we need to save the items somewhere.

Synchronous Work

Adding persistence will cause another problem: all of our interactions with the ToDoRepository are synchronous. That means that our I/O will tie up the main application thread, freezing our UI while that I/O is being done.

This is not good.

Instead, we need to switch to an asynchronous interaction with the repository. For example, when we save() a ToDoModel, it should not be a blocking call. Instead, the actual work for saving the data should happen on a background thread, with us finding out about the result asynchronously. That way, the UI remains responsive while we are doing the I/O.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.