Android Question StartServiceAt not worked android 8+

mohammad be

Member
Hello to all
This is my code in a service

But in Android 8, when the user deletes the program from memory
The declaration remains, but the order
StartServiceAt (me, DateTime. Now 30,000, correct)
Does not work
B4X:
#Region  Service Attributes
    #StartAtBoot: True
    '#StartCommandReturnValue: android.app.Service.START_STICKY
#End Region
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private nid As Int = 1
    Public Wsh As WebSocketHandler
    Public WshLink As String="ws://45.156.xxx.xxx:xxxx/ws"
    Public WshID As String=""
    Public WshStatus As Boolean=False
    Public GetChatAllStatus As List
    Private pw As PhoneWakeState
    Private rm As RingtoneManager
    Private ringtone As JavaObject
End Sub
Sub Service_Create
    Wsh.Initialize(Me,"wsh")
    GetChatAllStatus.Initialize
    pw.PartialLock
    Service.AutomaticForegroundMode=Service.AUTOMATIC_FOREGROUND_NEVER
'    Service.AutomaticForegroundMode=Service.AUTOMATIC_FOREGROUND_ALWAYS
End Sub
Sub Service_Start (StartingIntent As Intent)
    Service.StartForeground(nid,CreateNotification("...",""))
    StartServiceAt(Me, DateTime.Now + 30000, True)
    SocketChk_Tick
End Sub
 

mohammad be

Member
B4X:
Sub UpdateStatus
    If Wsh.ws.Connected Then
        Log("Status: Connected")
        timer.Enabled=False
        Dim n As Notification=CreateNotification("Connected.","")
        n.Notify(nid)
    Else
        Log("Status: Disconnected")
        Dim n As Notification=CreateNotification("DisConnected.","")
        n.Notify(nid)
    End If
End Sub
Sub wsh_Connected
    WshStatus=True
    UpdateStatus
End Sub
Sub wsh_Closed (Reason As String)
    WshStatus=False
    UpdateStatus
End Sub
Sub SocketChk_Tick
    If Not(Wsh.ws.Connected) Then
        Wsh.Connect(WshLink)
        Log("Try...")
    End If
End Sub
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
On newer versions of Android (8 and up), startserviceat needs a minimum of 15 to 30 minutes as the time period. Any shorter periods are most likely ignored by Android.

 
Upvote 0

mohammad be

Member
On newer versions of Android (8 and up), startserviceat needs a minimum of 15 to 30 minutes as the time period. Any shorter periods are most likely ignored by Android.

Tanks
 
Upvote 0
Top