Italian Activity_Pause

Fulvio75

Well-Known Member
Licensed User
Non mi è chiara una cosa... In Activity_Pause non è possibile inserire Wait For per aspettare che la sub attesa faccia quello che deve fare?
Ho notato che quando mando in pausa l'app il codice della sub attesa non viene eseguito

B4X:
Sub Activity_Pause (UserClosed As Boolean)

    Functions.Write_Log("Applicazione in Pausa",False)
    
    'NON ENTRA QUI
    wait for Test
        
End Sub
 

Sagenut

Expert
Licensed User
Longtime User
Se continuasse a lavorare non sarebbe in pausa. :)
 

Fulvio75

Well-Known Member
Licensed User
Se continuasse a lavorare non sarebbe in pausa. :)
quindi prima di entrare in pausa non può attendere... ci deve entrare a cannone e stop?
se prima devo attendere lo scollegamento, termine, calcoli quindi non posso farlo?

nemmeno il do while funziona, ho provato
 

Sagenut

Expert
Licensed User
Longtime User
Credo che ti dia giusto un attimo per fare un save state dei dati che vuoi per per ripristinare la situazione al rientro.
 

Fulvio75

Well-Known Member
Licensed User
Credo che ti dia giusto un attimo per fare un save state dei dati che vuoi per per ripristinare la situazione al rientro.
si devo ripetere il codice che mi serve dentro in pause, se richiamo delle sub resumable non ci entra
 

LucaMs

Expert
Licensed User
Longtime User
Si, viene eseguito tutto il codice che scrivi nella Pause ma Wait For passa il flusso altrove e POI gli dovrebbe venire restituito ma a quel punto non è più possibile, in quanto l'Activity sarà andata in pausa.

Passate a progetti B4XPages; questo è uno dei tanti casi in cui otterresti ciò che vuoi fare.

P.S. Forse, perché il flusso tornerebbe alla routine evento, ma comunque con l'app già in background, eh.
 
Last edited:

Fulvio75

Well-Known Member
Licensed User
Si, viene eseguito tutto il codice che scrivi nella Pause ma Wait For passa il flusso altrove e POI gli dovrebbe venire restituito ma a quel punto non è più possibile, in quanto l'Activity sarà andata in pausa.

Passate a progetti B4XPages; questo è uno dei tanti casi in cui otterresti ciò che vuoi fare.

P.S. Forse, perché il flusso tornerebbe alla routine evento, ma comunque con l'app già in background, eh.
provato riprende il codice chiamato in pause quando fa Resume quindi in Pause non si può fare quasi nulla, va in pausa e basta 😭
 

LucaMs

Expert
Licensed User
Longtime User
Non so cosa tu debba fare, esattamente.
Se non è una cosa grafica, dopo il wait for, in un progetto B4XPages puoi farlo, nell'evento B4XPage_Background (o CloseRequest o Disappear, dipende).
(Veramente anche se è grafica, solo che non la vedrai finché non riporterai la pagina/app in primo piano).
 

Fulvio75

Well-Known Member
Licensed User
Non so cosa tu debba fare, esattamente.
Se non è una cosa grafica, dopo il wait for, in un progetto B4XPages puoi farlo, nell'evento B4XPage_Background (o CloseRequest o Disappear, dipende).
(Veramente anche se è grafica, solo che non la vedrai finché non riporterai la pagina/app in primo piano).
Ok però uso le Activity 🤣 🤣 🤣
 

Fulvio75

Well-Known Member
Licensed User
E fai "male".

Prova a spiegare "nel dettaglio" cosa vorresti ottenere, magari è possibile anche coi progetti "normali"
Il problema l'ho chiarito nel post #6
Quando l'app va in pausa devo disabilitare delle interrogazioni BT
L'app gira e interroga una scheda collegata via BT e aspetta una risposta poi prende il dato e lo tratta.
Quando l'app va in pausa per qualsiasi motivo deve prima attendere il termine dell'interrogazione BT poi chiudere la connessione e andare in pausa.
Andando in pausa non entra in wait for qui di non attende la sub che fa il lavoro di gestione scheda BT
 

Filippo

Expert
Licensed User
Longtime User
Quando l'app va in pausa devo disabilitare delle interrogazioni BT
L'app gira e interroga una scheda collegata via BT e aspetta una risposta poi prende il dato e lo tratta.
Quando l'app va in pausa per qualsiasi motivo deve prima attendere il termine dell'interrogazione BT poi chiudere la connessione e andare in pausa.
Andando in pausa non entra in wait for qui di non attende la sub che fa il lavoro di gestione scheda BT
Prova cosi:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        HandleBackKey
        Return True
    End If
    Return False
End Sub

Private Sub HandleBackKey
    'Fai quello che vuoi
    wait for Test
    Activity.Finish
End Sub
 

OliverA

Expert
Licensed User
Longtime User
Usando Google Traduttore:

Se desideri continuare a utilizzare le Attività, dovrai utilizzare un servizio in primo piano per gestire la disconnessione BT. Puoi anche provare un ricevitore (Android gli concede circa 20 secondi per completare il suo lavoro)

(If you want to keep using Activities, then you will have to use a foreground service to handle your BT disconnection. You may also try a Receiver (Android gives it about 20 seconds to finish its work))
 

LucaMs

Expert
Licensed User
Longtime User
Prova cosi:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        HandleBackKey
        Return True
    End If
    Return False
End Sub

Private Sub HandleBackKey
    'Fai quello che vuoi
    wait for Test
    Activity.Finish
End Sub
Potrebbe non essere l'ideale, in quanto se lanci Activity.Finish poi se riattivi l'app l'Activity sarà ricreata da zero, cosa che @Fulvio75 potrebbe non volere.

Credo che più semplicemente...
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Wait For Test
    End If
End Sub
 

OliverA

Expert
Licensed User
Longtime User
KeyCode = KeyCodes.KEYCODE_BACK
Usando Google Traduttore:
Il problema che vedo con questa soluzione è che il tasto Indietro non è l'unico modo in cui è possibile attivare Activity_Pause

(The issue I see with that solution is that the Back Key is not the only way that Activity_Pause can be triggered)
 

Fulvio75

Well-Known Member
Licensed User
Prova cosi:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        HandleBackKey
        Return True
    End If
    Return False
End Sub

Private Sub HandleBackKey
    'Fai quello che vuoi
    wait for Test
    Activity.Finish
End Sub
Non è Activity_Pause
 

Fulvio75

Well-Known Member
Licensed User
Potrebbe non essere l'ideale, in quanto se lanci Activity.Finish poi se riattivi l'app l'Activity sarà ricreata da zero, cosa che @Fulvio75 potrebbe non volere.

Credo che più semplicemente...
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        Wait For Test
    End If
End Sub
Esatto
 

Fulvio75

Well-Known Member
Licensed User
Usando Google Traduttore:
Il problema che vedo con questa soluzione è che il tasto Indietro non è l'unico modo in cui è possibile attivare Activity_Pause

(The issue I see with that solution is that the Back Key is not the only way that Activity_Pause can be triggered)
Esatto possono esserci altre app che mandano in pausa l'app senza dover premere nessun bottone
 

Fulvio75

Well-Known Member
Licensed User
Per me l'ideale è fare tutto da Activity_pause
Se no su resume reinizializzo tutto e stop
 

OliverA

Expert
Licensed User
Longtime User
Per me l'ideale è fare tutto da Activity_pause
Usando Google Traduttore:
Ma tu non puoi. Questa non è una limitazione di B4A o Wait For, è semplicemente come funziona il ciclo di vita di Android e come funziona (rabbrividisce) l'implementazione Bluetooth di Android. So che l'utilizzo di un servizio in primo piano funziona, sarebbe interessante se funzionasse anche un ricevitore (poiché tutto ciò che stai cercando di fare è disconnettere BT e se ciò può essere fatto in meno di 20 secondi, dovresti andare bene con l'utilizzo di un ricevitore)

Using Google Translate:
But you cannot. This is not a limitation of B4A or Wait For, it's just how the Android life cycle works and how (shudder) Android's Bluetooth implementation works. I know using a foreground service works, it would be interesting if a Receiver would also work (since all you are trying to do is disconnect BT and if that can be done under 20 seconds, you should be fine with using a Receiver)
 
Top