When initialize,before set the calculation you have to get value from list picker and then set the math block.
You can retrieve expiration data from tinyDb but you have to save it the first time , after saving in tinyDb all the time you start app you will get the expiration date
Mi spiego meglio. Quando parte l'app deve avere già salvato questo dato altrimenti bisogna fornirlo. Hai due possibilità
Quando carica lo screen prima selezioni la data e poi imposti il calcolo
La prima volta salvi la data di scadenza nel tinyDb ed a ogni ingresso valuti se c'è il valore nel tinyDb e lo prelevi per il calcolo .
Obviously, by first selecting the expiration date and then the calculation; everything is great. If instead I save the calculation in the TinyDB; even if I run the app the following day; it tells me that the remaining days are the same as the day before, since it can't run in the background.
The calculation is always performed every time I go to indicate the expiry date; otherwise the same days remain..since it doesn't work in the background. I hope they can integrate into Mit App Inventor one day; the possibility that the apps can also work in the background. @Taifun has already taken a first step in this direction..with his extension "Taifun Alarm Manger".
Happy Sunday
If you save the expiration day in the tinyDb you will find it when open the screen. The only thing that doesn't work is a notification when app is closed. Background task works only with some extension
I fully agree with you, if every time I open the app; I have to calculate a different expiration date. Instead the expiry date is always the same (e.g. 20 days left)..so if I open the app after two days; he will have to tell me that there are 18 more days to go.
If you save 30/03/2023 as expiration day when you open the app in 20/03/2023 it will show you 10 days to go. If you open the app in 25/03/2023 it will show 5 days to go. With some extra code in 5/04/2023 you will also show : it's 5 days after expiration day and so on
You have to use TinyDb. The first time you set the value and then everyday you open app countdown appears.
In your code ,when screen initialize first block has to be TinyDb get value . Set it in a variable and use it for the calculation
Hai cambiato totalmente la logica ? Come consiglio prova a scrivere i vari passaggi che ti servono e poi lo traduci in codice.
Controlla bene che hai due variabili con nomi simili rimanenti e restanti .
Controlla sempre il tipo di dati , non puoi sottrarre date ma il loro corrispettivo in millisecondi, le operazioni matematiche possono essere fatte solo tra numeri e non altri formati.
Il vecchio codice era finito, dovevi solo anticipare la chiamata al tinyDb
L'avevo anticipata la chiamata al TinyDB; ma la scadenza caricata corrisponde sempre agli stessi giorni. Se a te non ti dispiace, ti mando direttamente il file AIA; e così potrai vedere tutte le operazioni
In giorni rimanenti immagino ci sia un numero , tipo 20 o 10. Nel tiny invece devi salvare la data di scadenza e dopo usarla come serve, così la prima volta usi il date picker per selezionare la data di scadenza e la salvi nel tiny così quando ti serve è lì.
Apri l'app recuperi da la data di scadenza e la usi per il calcolo, per visualizzarla o quello che ti serve . Naturalmente cambiando il formato a seconda dell'uso .
Edit Usa direttamente l'instant del data picker e i vari blocchi format per modificare la visualizzazione