Android Question Change activity Problem

GaNdAlF89

Active Member
Licensed User
Longtime User
In my app I have three activities: Login, Selection and Produce. In Produce activity I use the barcode scanner with ABZxing library. In this case, if barcode isn't read in some seconds (readInterval), I return to Produce activity with this code:

B4X:
Sub Activity_Pause (UserClosed As Boolean)

If Global.kiosk = True AND Global.currentActivity = "Produce" Then
     
        If Global.flagBarcode = False Then
            StartServiceAt(Kiosk_Service,DateTime.Now,False)
        Else
            StartServiceAt(Kiosk_Service,DateTime.Now + readInterval,False)
        End If
     
End If

End Sub

Kiosk_Service module restart the Produce activity if it is paused:
B4X:
Sub Service_Start (StartingIntent As Intent)
 
    Service.StartForeground(1, Notification)
 
    KioskTimer.Enabled = True
 
End Sub

Sub Service_Destroy
 
    KioskTimer.Enabled = False
 
    Service.StopForeground(1)
 
End Sub

Sub KioskTimer_Tick
 
    Global.flagBarcode = False
  
    If IsPaused(Global.currentActivity) Then
        StartActivity(Global.currentActivity)
    End If
 
    KioskTimer.Enabled = False
  
End Sub

I have a problem only if the barcode scanner is closed by Kiosk_Service, when I close Produce activity to return to Selection activity, the barcode scanner is resumed and Kiosk_Service doesn't work.
It is as if Android schedule the barcode scanner instead of my app when i want to return to Selection activity to Produce activity. What is the problem?
 

GaNdAlF89

Active Member
Licensed User
Longtime User
Upvote 0

GaNdAlF89

Active Member
Licensed User
Longtime User
You can catch the back key and start the first activity and then call Activity.Finish.

Thanks, I have already tried to do this with this code, but it doesn't work.
B4X:
Global.currentActivity = "Selection" 
StartActivity(Global.currentActivity) 'start Selection activity
Activity.Finish 'close Production activity

I've also tried with this
B4X:
Dim tIn As Intent
tIn.Initialize(tIn.ACTION_MAIN,"")
tIn.SetComponent("<packagename>/.selection")
StartActivity(tIn)
Activity.Finish
but the result is the same. Why?
 
Upvote 0

GaNdAlF89

Active Member
Licensed User
Longtime User
I put it in the click event of a button, that I use only to change activity (close Produce activity and start Selection acitvity).

B4X:
Sub ButtonExit_Click
 
Dim res As Int
res = Msgbox2("<message>","<title>","YES","","NO",Null)

If res = DialogResponse.POSITIVE Then
   
    Global.currentActivity = "Selection"
    StartActivity(Global.currentActivity) 'start Selection activity
    Activity.Finish

End If

End Sub
 
Upvote 0
Top