Android Question Fatal Exception: android.app.RemoteServiceException Context.startForegroundService()

Status
Not open for further replies.

scsjc

Well-Known Member
Licensed User
Longtime User
I have this error from service:

B4X:
Fatal Exception: android.app.RemoteServiceException
Context.startForegroundService() did not then call Service.startForeground()
android.app.ActivityThread$H.handleMessage

it may be that the cause is for executing a StartServiceAt within the Sub Service_Destroy ?

B4X:
Sub Service_Destroy
    StartServiceAt(Me, DateTime.Now + 300 * DateTime.TicksPerSecond, True)
End Sub
 

scsjc

Well-Known Member
Licensed User
Longtime User
Not enough information...

Is this the starter service?

Are you changing the automatic foreground mode?

Also post the full error message.

on service_create :
B4X:
Sub Service_Create
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
end sub

the service launch via: #StartAtBoot: True, and the service not is starter
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
Not enough information...

Is this the starter service?

Are you changing the automatic foreground mode?

Also post the full error message.


I see in playstore that says "no available location"
The service uses GPS to do user tracking, I don't know if this refers to something from the GPS, or to something from the service.


1581496440182.png
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
Not enough information...

Is this the starter service?

Are you changing the automatic foreground mode?

Also post the full error message.


I have been reading on the internet on this subject, and I have found in: https:// medium.com/pongploydev/why-start-the-service-on-android-o-and-encounter-a-problem-record-context-startforegroundservice-3c8ddd8969ef

This paragraph:
"After the system creates the service, the app has 5 seconds to call the service’s startForeground() method to display the user-visible notification for the new service. If the app does not call startForeground() within this time limit, the system will stop the service and declare the application as ANR."

I use the code from your example "Background location tracking" - https://www.b4x.com/android/forum/threads/background-location-tracking.99873/#content

But I added that: -> when the "user_is_tracking=false" does not execute tracker tracking, and I end the service with: "lock.ReleasePartialLock & Service.StopAutomaticForeground".... code:


B4X:
#Region  Service Attributes
    #StartAtBoot: True
#End Region

Sub Process_Globals
    Dim user_is_tracking As Boolean
    Private nid As Int = 1
    Private GPS As GPS
    Private Tracking As Boolean
    Private LastUpdateTime As Long
    Private lock As PhoneWakeState
End Sub

Sub Service_Create
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves
    GPS.Initialize("gps")
    lock.PartialLock
End Sub

Sub Service_Start (StartingIntent As Intent)
    If user_is_tracking Then
        Service.StartForeground(nid, CreateNotification("..."))
        StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True)
        Track
    Else
        lock.ReleasePartialLock
        Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
    End If
End Sub

Public Sub Track
    If Tracking Then Return
    If Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION) = False Then
        Log("No permission")
        Return
    End If
    GPS.Start(0, 0)
    Tracking = True
End Sub
.
.
.


I think that I do not close the service well, and those 5 seconds are indicated and the system stops the service declaring application as ANR.
This is correct? How can it be solved?

thanks :)
 
Upvote 0

Cebuvi

Active Member
Licensed User
Longtime User
I have the same problem with a service. I have read and studied the tutorial and cannot find the solution. Some help?
Thanks
 
Upvote 0
Status
Not open for further replies.
Top