The aia file aims to create an alarm system based on a background system created with Itoo.
Reliability is maximum and it will always notify us exactly at the hour and minute marked as the alarm.
The app would manage the service, auto-starting when there are pending alarms and closing when there are no pending alarms in the database.
The application uses the following components
The aia consists of two parts:
1.- The Activity part
2.- The Service Part
1. In the activity part there are the following blocks
start
This procedure will start with Screen1.Initialize and what it does:
-
Create the shared variable "musicalarma" in which we will save the source of the player component.
-
Manage the shared variable "alarmanow" that is updated by the service every time an alarm occurs. From this variable, apart from closing it again as the block does, the activity could be told to do anything else.
-
Present the database of pending alarms in a Listview.
startservice
Start the service if it is no longer open, it is used when we create an alarm
createalarm
It creates two types of alarm depending on what we indicate in the "Type" variable, one based on dates and another simple one based on seconds, for this:
-
We calculate the milliseconds of the created alarm based on a TimerPicker and a DatePicker (date type) or a Textbox (seconds type) and the clock component
-
We empty the data from the shared variable "listaalarmas" into a local variable "lista"
-
If the time of the created alarm is greater than the current time, it is added to the "lista" variable
-We order the list variable from most recent to least recent.
-We save the shared variable "listaalarmas" with the data of the local variable "lista"
-We present the database in the ListView
-If the service is not on, we turn it on.
alarmdatabase
- We present the database saved in the variable in the ListView
The aia also allows you to delete an already established alarm by clicking on a record in the lisview that will open a dialog box.
2. In the Service part there are the following blocks
alarm
This block is called every time we start the service
-Register the Clock and Play components
-Start the clock
-It tells the play component what its source is through the shared variable "musicalarma"
-Register the clock Timer event through the data procedure
data
In this procedure we are going to tell the service what to do each time the Clock Timer event occurs.
-We start a local variable "lista" with the data from the shared variable "listaalarmas"
-We compare the current time in "yyyy/MM/dd HH:mm:ss" format with the data from the first record of the "lista" variable with the same format.
-If they match, an alarm is produced and the following actions are activated
- A notification is created with the title "Alarm (click to finish)" and in the subtitle the alarm data in "dd/MM/yyyy HH:mm" format.
This notification has the characteristic that clicking on it opens the main activity (Screen1).
2.Set the shared variable "alarmanow" to true
3.The Player component starts playing
4.Delete the first record of the local variable "lista", since this alarm has already passed
5.Save the shared variable "listaalarmas" with the data of the local variable "lista"
-The service checks that the main activity has set the shared variable "alarmanow" to false, in this case it stops the player and cancels the notification
-If the service verifies that the shared variable "listaalarmas" is an empty list, it turns off the Timer and closes the service
It is important in the compiled application that if the phone is a Xiaomi or a Samsung it is necessary to configure the battery saving as "No Restrictions"
AlarmaItoo.aia (163.6 KB)
all the best