Android Question Internet automatic disconnect

Dario126

Member
Licensed User
Longtime User
When screen is off, my mobile disconnect from internet in about 15 min (not sure how this mode is called and is it implemented on OS level or is it device specific). After I turn on mobile, it reconnects immediately.

Sure I can change this behavior in settings, but I want that my app is universal and works on all devices without too much user interventions. Problem is that my app is depending on fresh data every five minutes.

Can I force reconnect to internet (by code in my app) for this case ?

PS: i'm aware about push framework, but it looks overkill and too complicated at the moment.
 

Dario126

Member
Licensed User
Longtime User
I tried it now with partial lock like this:

B4X:
Sub PE_ConnectivityChanged (NetworkType As String, State As String, Intent As Intent)
    If State="CONNECTED" Then
    Else
        StartServiceAt("", DateTime.Now+10*1000, True)
    End If
End Sub

Sub Service_Start (StartingIntent As Intent)  
        say ("service started, wait 10 sec then partial lock")
        WS.PartialLock
        Timer2.Initialize("timer2", 10000)      
End Sub

Sub timer2_tick
    say("timer 2 tick")
    WS.ReleasePartialLock
    InvokeDefSettings
    Timer2.Enabled=False
End Sub

Sub InvokeDefSettings
Dim s As String

    say("invoke settings")

    'PREPARE URL
    s="http://..."  'this is cut now on purpose
  
    'INVOKE POST
    Log(" INVOKE: InvokeDefSettings")      
    Dim request As HttpRequest
    request.InitializeGet(s)
    request.Timeout=30*1000
    If HttpClient1.Execute(request, 2) = False Then Return

End Sub

Sub Http_ResponseSuccess (Response As HttpResponse, TaskId As Int)
say("HTTP RESPONSE")
Timer1.Enabled=False
End Sub

but response never arrives and Http_ResponseSuccess sub is never called .. When mobile is not in sleep, this invoke and response works normally. Problem is that device is not reconnecting after partial wake up.
 
Upvote 0
Top