Android Question Detect Back Button Problem

Marco Maria Vilucchi

Active Member
Licensed User
Hi all,
In my app I need to update MySql when Back Button is pressed.
Then I detect Back Button and do an update:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean

    If KeyCode = KeyCodes.KEYCODE_BACK Then
        messaggio="detect back button"
        LogColor(messaggio,Colors.Magenta)

        Main.pulsantepremuto=1
        Main.pulisci=1
        Log("Main.pulisci=" & Main.pulisci)

'    aggiorno i messaggi
        Dim jobx As HttpJob
        Main.Qry="update co02messaggi set co02letto=1,co02lettotime='" & wtime & "' where co02time<='" & wtime & "' and co02userda=" & Main.manutentekey & " and co02usera=" & Main.nickdestinatariokey
        messaggio="Qry " & Main.qry
        Log(messaggio)
        jobx.Initialize("Job2", Me)
        jobx.PostString(Main.ServerUrl, Main.Qry)
    End If

End Sub

The problem is that previous page (that is named homepage) starts with Activity RESUME and then, immediately, starts Activity PAUSE.
Then restart the page where I pressed BACK.

This is the log:
B4X:
detect back button
Main.pulisci=1
Qry update co02messaggi set co02letto=1,co02lettotime='' where co02time<='' and co02userda=7 and co02usera=8
** Activity (chatsegreta) Pause, UserClosed = true **
Activity pause done - pulsantepremuto=1
** Activity (homepage) Resume **
Main.pulisci=1
** Activity (homepage) Pause, UserClosed = false **
Activity Pause
** Activity (chatsegreta) Create, isFirst = false **
Qry Select * FROM co01utenti where co01key=8
** Activity (chatsegreta) Resume **
RESUME RESUME RESUME RESUME RESUME
Main.nickdestinatariokey 8
JobName = Job2, Success = true
JobName = Job0, Success = true
co01identificativo marcovi co01password marcovi co01sesso 1 co01maggiorenne 1 co01immagine 8.jpg
http://www.mamavisoftware.it/contravvenzioni/fotoutenti/8.jpg
Qry Select * FROM co02messaggi where co02letto=0 and ((co02userda=7 and co02usera=8) or (co02userda=8 and co02usera=7)) order by co02time
JobName = Job1, Success = true
RiempiItem 0 totta 0

This is the code on Homepage:
B4X:
Sub Activity_Resume
    Log("Main.pulisci=" & Main.pulisci)
    If Main.pulisci=1 Then
        Main.pulisci=0
        numerotarga.Text=""
    End If
    If Main.pulisci=2 Then
        numerotarga.Text=""
        Activity.Finish
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Log("Activity Pause")
End Sub
From the Log we can see that Main.pulisci=1

PAY ATTENTION: If I cancel from code the query update, all works (I tryed with Jobdone and with wait for... same thing)

Why it happens and how can I solve?
Thanks
Marcom
 

Marco Maria Vilucchi

Active Member
Licensed User
I allways used Me to initialize. Witch different activity may I use?
Tell me an example, please.
I don't make a download, but a MySql query update....
 
Upvote 0

DonManfred

Expert
Licensed User
Stick on Solution 2
 
Upvote 0
Top