Italian Uscire veramente dalla applicazione

Federico1968

Member
Licensed User
Longtime User
Ciao a tutti,
Ho realizzato una applicazione che esegue tra l'altro un file mp3 in loop.
Ho intercettato il back button per uscire dall'applicazione dove chiedo con un messagebox se "vuoi uscire veramente ?".
Tutto funziona se rispondo "OK" alla domanda, l'app si chiude e spegne il loop del mp3.
ma....
Se l'utente preme nuovamente il tasto back, l'applicazione esce lo stesso e non spegne il file sonoro.
Dove sbaglio ?
Grazie mille in anticipo

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    If KeyCode=KeyCodes.KEYCODE_BACK Then
        Dim domanda As Int
        domanda = Msgbox2("Vuoi uscire veramente ?","","Ok","","Annulla",Bmp)
        If domanda =DialogResponse.POSITIVE Then
            Pw.ReleaseKeepAlive
            MP.Stop
            ExitApplication
        Else If domanda=DialogResponse.NEGATIVE Then
        Return True
        End If
    End If
End Sub
 

LucaMs

Expert
Licensed User
Longtime User
Ciao a tutti,
Ho realizzato una applicazione che esegue tra l'altro un file mp3 in loop.
Ho intercettato il back button per uscire dall'applicazione dove chiedo con un messagebox se "vuoi uscire veramente ?".
Tutto funziona se rispondo "OK" alla domanda, l'app si chiude e spegne il loop del mp3.
ma....
Se l'utente preme nuovamente il tasto back, l'applicazione esce lo stesso e non spegne il file sonoro.
Dove sbaglio ?
Grazie mille in anticipo

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    If KeyCode=KeyCodes.KEYCODE_BACK Then
        Dim domanda As Int
        domanda = Msgbox2("Vuoi uscire veramente ?","","Ok","","Annulla",Bmp)
        If domanda =DialogResponse.POSITIVE Then
            Pw.ReleaseKeepAlive
            MP.Stop
            ExitApplication
        Else If domanda=DialogResponse.NEGATIVE Then
        Return True
        End If
    End If
End Sub


Eh, non sbagli; o meglio, se sbagli, siamo in due :).

Visto che serve anche a me, ora mi metto a cercare una soluzione (visto che altruismo? hehehe)

P.S. Io però toglierei quel: "If domanda=DialogResponse.NEGATIVE Then"
Else
Return True ' comunque!!
 

LucaMs

Expert
Licensed User
Longtime User
Intanto, potresti mettere una sub con le due righe:
Pw.ReleaseKeepAlive
MP.Stop

tipo Sub FermaTutto

poi, nella Activity_Pause:

if UserClosed then
FermaTutto
end if

(almeno, anche se esce col doppio Back, fermi il play)
 

LucaMs

Expert
Licensed User
Longtime User
Trovato.

Questa risposta di Erel.

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
  Select KeyCode
    Case KeyCodes.KEYCODE_BACK
      CallSubDelayed(Me, "HandleBackKey")
      Return True
  End Select
  Return False
End Sub

Sub HandleBackKey
    Dim Answ As Int
    Dim txt As String
    txt = "Vuoi davvero uscire da NOME_TUA_APP?"
    Answ = Msgbox2(txt, "ATTENZIONE", "Sì", "", "No", Null)
    If Answ = DialogResponse.POSITIVE Then
        CloseApp
    End If
End Sub

Sub CloseApp
    Pw.ReleaseKeepAlive
    MP.Stop
    ExitApplication
End Sub
 
Last edited:

Federico1968

Member
Licensed User
Longtime User
Ho verificato, se tocchi l'activity al di fuori della dialog non accade nulla.
Rimane in attesa di "Ok" o "Annulla":confused:
 

Federico1968

Member
Licensed User
Longtime User
Trovato.

Questa risposta di Erel.

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
  Select KeyCode
    Case KeyCodes.KEYCODE_BACK
      CallSubDelayed(Me, "HandleBackKey")
      Return True
  End Select
  Return False
End Sub

Sub HandleBackKey
    Dim Answ As Int
    Dim txt As String
    txt = "Vuoi davvero uscire da NOME_TUA_APP?"
    Answ = Msgbox2(txt, "ATTENZIONE", "Sì", "", "No", Null)
    If Answ = DialogResponse.POSITIVE Then
        CloseApp
    End If
End Sub

Sub CloseApp
    Pw.ReleaseKeepAlive
    MP.Stop
    ExitApplication
End Sub


Grazie mille, ora è tardi ma domani provo sicuramente.
 
Top