Android Question StartForeground crashes

Scantech

Well-Known Member
Licensed User
Longtime User
What does this error mean?

Context.startForegroundService() did not then call Service.startForeground(), InvisibleToUser

"main" prio=5 tid=1 Native | group="main" sCount=1 dsCount=0 flags=1 obj=0x73a999f0 self=0xacbda000 | sysTid=9157 nice=-4 cgrp=default sched=0/0 handle=0xb058a4a4 | state=S schedstat=( 782738481 164038913 1702 ) utm=50 stm=27 core=7 HZ=100 | stack=0xbe1ce000-0xbe1d0000 stackSize=8MB | held mutexes=

#00 pc 0000000000018d88 /system/lib/libc.so (syscall+28)

#01 pc 00000000000b77d1 /system/lib/libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*)+80)

#02 pc 00000000003e1db9 /system/lib/libart.so (art::GoToRunnable(art::Thread*)+300)

#03 pc 00000000003e1c5d /system/lib/libart.so (art::JniMethodEnd(unsigned int, art::Thread*)+8)

#04 pc 0000000000183f1f /system/framework/arm/boot-framework.oat (Java_android_os_MessageQueue_nativePollOnce__JI+102)

at android.os.MessageQueue.nativePollOnce (Native method)

at android.os.MessageQueue.next (MessageQueue.java:325)

at android.os.Looper.loop (Looper.java:142)

at android.app.ActivityThread.main (ActivityThread.java:6626)

at java.lang.reflect.Method.invoke (Native method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:438)

at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:811)
"Jit thread pool worker thread 0" tid=2 Native

B4X:
Sub Service_Create
'TripGPSDistance

    CheckPreferenceState
 
    'we don't need this when gps setting is off. must avoid this or crashing can occur
    If StateManager.blnUseGPS = True Then
        Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER 'we are handling it ourselves
    End If
 
    GPS1.Initialize("GPS")
    tmrTrip.Initialize("tmrTrip", 500)                         'every 500 milliseconds
    tmrTripSaveData.Initialize("tmrTripSaveData", 60000)     '1 minutes
    PhoneEvent.Initialize("PhoneEvents")
   
    StateManager.LoadStateTrip                'load these
    StateManager.LoadStateMaintenance        'load these at first startup
    StateManager.LoadStateSpeedLimiter        'load speed limiter value
   
    Starter.pws.PartialLock                    'Important so it will not CPU Sleep

    TripIcon1 = LoadBitmapResize(File.DirAssets, "tripicon.png", 24dip, 24dip, True)
    TripIcon2 = LoadBitmapResize(File.DirAssets, "mainicon.png", 24dip, 24dip, True)

End Sub
Sub Service_Start (StartingIntent As Intent)

    StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True) '30 minutes

    'avoid this if gps settings in app is off
    If StateManager.blnUseGPS = True Then

        Service.StartForeground(1, CreateNotification("..."))
   
        tmrNotification_OBD_GPS_Mode_Status(2)
 
        TurnOnTmrTrip
    Else
        Service.StopAutomaticForeground
    End If
 
End Sub

B4X:
Sub Activity_Resume
'This is Main resume
     CallSubDelayed(TripGPSDistance, "StartTimerandNotification")
B4X:
Public Sub StartTimerandNotification
  'TripGPSDistance

    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
    Service.StartForeground(1, CreateNotification("..."))
 
    tmrNotification_OBD_GPS_Mode_Status(2)
 
    TurnOnTmrTrip

End Sub
 
Last edited:

Scantech

Well-Known Member
Licensed User
Longtime User
I'm not sure that the low level error is related to this code. Are you calling DoEvents or showing a modal dialog (Msgbox) somewhere in your code?

Yes modal or doevents elsewhere, there is only 1 report of this error. Hopefully that is the only one.

Previously, i had thousands of crash report and only on Android 9 because i was not calling Service.StartForeground(1, CreateNotification("...")) when using Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER. So i made adjustment and so far only that 1 report is showing.
 
Upvote 0
Top