Android Without a UI

When one thinks of designing an Android application, UI should always be at the top of the priority list. This should be the case especially because Android apps are interfaced with often due to the nature of the hardware and operating system. But what happens when you have to write an app without a minimal UI, an app that simply has to run endlessly and the only interface for the user is the display? Well, it becomes a little bit more complicated.

I was in charge of designing and writing the Sqreen 3.0 application responsible for playing advertisements on screens for users 24/7. These screens would be displayed in areas with high foot traffic such as bus stations and The Path in Toronto. Writing the application is not a very complex ordeal since there are only two main features that need to be hit:

  1. Able to log the screen into the backend CMS to receive advertisements.
  2. Maintain a playlist of advertisements and run them in a loop indefinitely.

The devil is in the details in this case: “run them in a loop indefinitely”. Indefinitely is a tough concept for an Android application. The OS itself runs garbage collection periodically and when there are instances where memory is low, the OS will kill the process to free up resources. The priority for these processes are generally managed by the OS itself, and it could be that it will kill your important service that maintains a connection to your database. If that were to happen, how do you detect it and start the service again? These concepts would not be required in an application running on more robust hardware with a different operating system.

To counter all of this I implemented some methods to restart pretty much everything that doesn’t run on the UI thread which is a substantial part of the application in our case. The UI thread is displaying a video constantly so we don’t want any interruptions especially given our lower-end hardware. Having fail-safes for every little detail is paramount in this case since this system will also be out of technicians’ hands and will need to be resilient to every sort of failure imaginable. Every time the system restarts the application starts anew and if there are bugs causing system crashes, a software restart is triggered.