the program paused on blocked screen. why?

jeronimovilar2

Member
Licensed User
Longtime User
Hi, sorry my english.
My program have a timer, when the cellphone is blocked (black screen) the timer is paused. How can i to do for the time not paused/stop??

or

how can i to change the time for the block screen to 40 minutes?

thanks
Jeronimo
Brazil
 

jeronimovilar2

Member
Licensed User
Longtime User
:(

I tryed StartServiceAt ("", DateTime.Now +1, True), but when i´ll to home ou the device is blocked the program (timer) is paused. :(

:sign0085:
 
Upvote 0

jeronimovilar2

Member
Licensed User
Longtime User
hi, (sorry my english)
The timer is ok, but when i touch the home button, the program is paused (LOG: **Activity (main) Pause, UserClosed = false **), so the timer is paused too. I need change the screen or blocked it, but not pause the timer. Can you help me?

My code:

B4X:
Sub Globals
   Dim Panel1 As Panel   
   Dim TEMPO As Int
   Dim LblCountDown1 As Label
   Dim VarLinguagem As String
   Dim corPainel As String
   Dim IMG1 As ImageView
   Dim TAM_tela As Int
   Dim RB2 As RadioButton
   Dim RB1 As RadioButton
   Dim RB3 As RadioButton
   Dim RB4 As RadioButton
End Sub
Sub Activity_Pause (UserClosed As Boolean)
   If UserClosed = False Then
      Log("and now????")      
   End If
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Main")
   StartServiceAt("", DateTime.Now, True)
   p.SetScreenBrightness(99) ' aumento o brilho ao máxino
   TAM_tela = 0
      
   Activity.Title = "Cronômetro 2.1"
   Dim LY As LayoutValues
   Dim X, Y As Int
   LY = GetDeviceLayoutValues
   X = LY.Width
   Y=  LY.Height
   ''log(X & "x" & Y)
   
   '----------- Cronometro -------------------
   Timer1.Initialize("Timer1", 1000)    
   CountDown2 = 0
   CountDown1 = 0
   TEMPO = RB1.Text
   Timer1.Enabled = False
   mp.Initialize2("mp")
   mp.Stop
   '------------------------------------------
End Sub

Sub Timer1_Tick
      If CountDown1 = 5 AND CountDown2 = 1 Then  ' ------- 5 min.
         Vibra_Toca (False, True, 5)
      End If
      If CountDown1 = 1 AND CountDown2 = 1 Then ' ----------- 1 min
         'ToastMessageShow(CountDown1 & ":" & CountDown2,False)
         Vibra_Toca (False, True, 2)      
      End If
      If CountDown1 = 0 AND (CountDown2 = 6 OR CountDown2 = 5 OR CountDown2 = 4 OR CountDown2 = 3 OR CountDown2 = 2)  Then  ' ------- últimos 5s
         'ToastMessageShow(CountDown2,False)
         Vibra_Toca (False, True, 2) ' ------- últimos 5 segundos
      End If
   If CountDown2 = 0 Then
      CountDown2 = 59
      CountDown1 = CountDown1 - 1
      If CountDown1 < 0 Then
         Timer1.Enabled = False
         CountDown2 = 0
         CountDown1 = 0
      End If
   Else
      CountDown2 = CountDown2 -1
   End If
   If CountDown2 < 10 Then
      LblCountDown1.Text = CountDown1 & ":0" & CountDown2
   Else
      LblCountDown1.Text = CountDown1 & ":" & CountDown2
   End If
   If CountDown2 = 0 AND CountDown1 <= 0 Then
      Timer1.Enabled = False
      Vibra_Toca (True, True, 0)
      CountDown2 = 0
      CountDown1 = 0
   End If
End Sub
Sub Vibra_Toca (vibra As Boolean, toca As Boolean, Musica As Int)
   mp.Initialize2("mp")
   mp.Stop
   Dim SOM As String
   vibrate.vibrate(250)
   If Musica = 5 Then
      SOM = "Alarme_05min.mp3"
      LblCountDown1.TextColor = Colors.Yellow
   Else If Musica = 0 Then  'final da bateria
      SOM = "ALARME_FINAL.mp3"
      LblCountDown1.TextColor = Colors.Red
   Else If Musica = 2 Then  '1 minuto ou 5 segundos
      'Msgbox(CountDown1 & ":0" & CountDown2,"")
      SOM = "ALARM_1S.mp3"
      LblCountDown1.TextColor = Colors.Red
   Else '  inicio da bateria
      SOM = "ALARME_INICIO.mp3"
      LblCountDown1.TextColor = Colors.White
   End If
   If toca = True Then
      p.SetRingerMode(p.RINGER_NORMAL)
      p.SetVolume(p.VOLUME_MUSIC,15,False)
      Dim r As Reflector
      r.Target = "ContentDir"
      r.Target = r.RunMethod("intern")
      'mp.Load(r.Target, "content://settings/system/ringtone")
      mp.Load(File.DirAssets,SOM)
      mp.Play
      vibrate.vibrate(500)
      'mp.Load(File.DirAssets,SOM)
      mp.Play
   End If
End Sub
Sub LblCountDown1_Click
   Dim SQL As String
   If CountDown2 = 0 AND CountDown1 <= 0 Then
      'mp.Stop
      CountDown2 = 00
      '-----Pegar o tempo do BUTTON
      CountDown1 = TEMPO
      Vibra_Toca(True, True, 15)
      Timer1.Enabled = True
      'mp.Initialize2("mp")
   End If   
End Sub
Sub Timer2_Tick
   conta_tempo = conta_tempo + 1
   Timer1.Enabled = False
   CountDown2 = 0
   CountDown1 = 0
   If conta_tempo = 3 Then
      Timer2.Enabled = False
   End If
'   Timer2.Enabled = False
   LblCountDown1.Text = CountDown1 & ":0" & CountDown2
End Sub
Sub LblCountDown1_LongClick
   mp.Stop
   Timer1.Enabled = False
   CountDown2 = 0
   CountDown1 = 0
   LblCountDown1.Text = CountDown1 & ":0" & CountDown2
End Sub

Sub RB1_CheckedChange(Checked As Boolean)
   If RB1.Checked = True Then
      TEMPO = RB1.Text
   End If
End Sub
Sub RB2_CheckedChange(Checked As Boolean)
   If RB2.Checked = True Then
      TEMPO = RB2.Text
   End If
End Sub
Sub RB3_CheckedChange(Checked As Boolean)
   If RB3.Checked = True Then
      TEMPO = RB3.Text
   End If
End Sub
Sub RB4_CheckedChange(Checked As Boolean)
   If RB4.Checked = True Then
      TEMPO = RB4.Text
   End If
End Sub
 
Upvote 0

drachmad

Member
Licensed User
Longtime User
Try playing with the sample attach.
If you can use StartServiceAt better use it.
I hope it helps.
 

Attachments

  • Timer Service.zip
    35 KB · Views: 203
Last edited:
Upvote 0

jeronimovilar2

Member
Licensed User
Longtime User
Thanks. Perfect.
How can i use to replace "ToastMessageShow" for call the program?
How to show the program again when it´s hide with a command?
 
Upvote 0
Top