Android Question StartService HttpUtils2Service when auto destroy it

Discussion in 'Android Questions' started by netsistemas, Nov 28, 2018.

  1. netsistemas

    netsistemas Member Licensed User

    I need the service HttpUtils2Service in starter service, because use method JOBDONE(Job as HTTPJO)

    All service are destroyed in ANDROID8+ (ok) when app is in BACKGROUND (this is a big problem).

    I write the code (access to a Web Service) in starter service, and with B4A 8.3+ the Starte Service are ignored and not destroyed (perfect), but.
    How avoid to destroy other serve and especially httputils2service

    i try to do a StartService( HttpUtils2Service)

    but, this is the trace crack in my app

    ** Service (httputils2service) Start **
    ** Service (starter) Destroy (ignored)**
    ** Service (httputils2service) Destroy **
    Solicitud a WS Enviada
    java.lang.IllegalStateException: Not allowed to start service Intent { cmp=nts.gpstoy/anywheresoftware.b4a.samples.httputils2.httputils2service }: app is in background uid UidRecord{11a349d u0a189 LAST bg:+1m2s807ms idle change:cached procs:1 seq(0,0,0)}
    at android.content.ContextWrapper.startService(
    at anywheresoftware.b4a.keywords.Common$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invoke(Native Method)
  2. Erel

    Erel Administrator Staff Member Licensed User

    You need to provide more information. How are you starting the job while your app is in the background?
  3. netsistemas

    netsistemas Member Licensed User

    There are only one serive: STARTER (i try to put in other service, but are destroyed).

    How to do a start a service and no destroy? that is the cuestin

    (i send you full code)

    Sub Service_Start (StartingIntent As Intent)
    'StartServiceAt(Me, DateTime.Now + (60 * 1000 * Minutos)  ,False)
                ToastMessageShow("GPStoy Service GO",False)
    ToastMessageShow("GPStoy Service Start " & LastException.Message ,True)
    End Try

    'nov 2018
        'Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
    End Sub

    Sub InitGPS
    If GPS1.GPSEnabled = False Then
    ToastMessageShow("Active la localizacion GPS"False)
    StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
    Log("GPS Iniciado")
    'el servicio solo se inicia 1 vez... el resto lo hace el gps1
    If modVarios.V_Config.ServicioActivo = "S" Then
                    modVarios.V_Config.HoraActiva = 
                    GPS1.Start(  modVarios.V_Config.Intervalo * 
    1000  , 0'Listen to GPS with no filters.
                    modVarios.V_Config.HoraActiva = 
                    GPS1 = 
    ToastMessageShow("GPStoy Servicio OFF en servicio"False)
    End If 
    End If
    'Msgbox (LastException.Message,"ERROR EN INITGPS")
    End Try
    End Sub
  4. Erel

    Erel Administrator Staff Member Licensed User

    You need to add another service and make it a foreground service if you want your app to run in the background.
  5. netsistemas

    netsistemas Member Licensed User

    I can't understand how to do a Foreground service.
    Maybe i no understand the concept between Service VS Activity and Foreground and background
  6. Erel

    Erel Administrator Staff Member Licensed User

    Create another service and call Service.StartForeground in that service.
  7. Erel

    Erel Administrator Staff Member Licensed User

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice