Android Question Design question: Timer-type app & use of services/activities

Misterbates

Active Member
Licensed User
I'm developing a timer/interval type app with the following characteristics:
* User can "design" a sequence of steps that can then be executed, and can save their sequence to device storage. They can re-open the saved sequence later.
* The app has three activities: A) show previously saved sequences plus a button to create a new sequence; B) show the steps in a re-opened sequence, add/delete/re-order steps, plus a button to execute the sequence; C) show the current execution, including which step is being executed, how long left etc.
* Once executing (see C) the app will display current step, time remaining etc. as well as generating various countdown-type sounds
* Once execution is finished, the app will display a summary of the executed steps, time taken etc. then drop back to the edit activity (see B).

My design-type questions are to do with using Services vs. using Activities:
1) The app should continue executing until done or the user says "stop". Even if the user switches to another app, even if the UI activities are destroyed by Android to free up resources. I'm thinking therefore that the part of the app that executes the steps and generates the sounds should be coded as a Service, or could be coded within the Starter service - make sense?
2) If the user does switch apps and the UI activities are destroyed, the Starter service will continue to run and when the user restarts the app (presses the app icon on the home screen), Android will switch to the (still active) starter service which will load the Main UI activity again even while the timer/sounds continue - correct?
3) In order to ensure a seamless user experience I'll need to keep track of the UI "breadcrumbs" that the user generated when starting the current execution (e.g. choose saved sequence -> view steps -> execute) so that if the UI activities are destroyed when the app restarts, the breadcrumbs can be used to put the user at the execute UI activity (and then later once done, then user will "return" to the view steps UI activity. Also correct?

In summary: Use a Service or the Starter service to execute a sequence of steps; use the UI activities to choose a sequence to execute, to show the user the current execution (by communicating with the Service/Starter service; on Activity startup, check for an active execution and if found, put the user where they were when the sequence was started.

Any design advice would be very much appreciated. :)
 
Last edited:

Misterbates

Active Member
Licensed User
In summary: Use a Service or the Starter service to execute a sequence of steps; use the UI activities to choose a sequence to execute, to show the user the current execution (by communicating with the Service/Starter service; on Activity startup, check for an active execution and if found, put the user where they were when the sequence was started.

Based on https://www.b4x.com/android/forum/threads/service-modules.7542/ and https://www.b4x.com/android/forum/t...-long-running-background-tasks.27065/#content here's what I'm planning:
* Add a service module and code it as if it were a class (properties/methods) that handles the execution activity
* In the service module call Service.StartForeground so that the app is tagged as Foreground and a notification icon appears in the taskbar.
* In the execute steps activity (item C above), start the service and use a timer to update the display based on calls to getXX "methods" in the service module.

The approach is for a long-running task similar to a music app playing music and should result in what I need - an app that can execute the sequence of steps (including generating sounds) even if the user switches away from the app.

Anything I should watch out for?
 
Upvote 0

Misterbates

Active Member
Licensed User
The concept works! Given my initial struggles with understanding how to combine a long-running (foreground) service with the Notification Builder library, I've posted example code that goes step by step from the original Erel "long download" example thru re-implementation with Notification Builder and then use of additional action buttons in the notification.

Hope this is useful: https://www.b4x.com/android/forum/threads/foreground-service-with-notification-builder.80398/
 
Upvote 0
Top