Hello everyone!
I am experiencing random crashes on an app in which i am testing background services in Android 8
I created a service (called check) that executes some instructions every one minute:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Randomly, let's say 2 or 3 times a day the app crashes with the following stacktrace:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Is there something that i can do for avoiding that crash?
			
			I am experiencing random crashes on an app in which i am testing background services in Android 8
I created a service (called check) that executes some instructions every one minute:
			
				B4X:
			
		
		
		Sub Service_Start (StartingIntent As Intent)
    Log("start")
    Dim Salva As TextWriter
    Salva.Initialize(File.OpenOutput(File.DirDefaultExternal, "Test.txt", True))
    Salva.WriteLine(DateTime.Date(DateTime.Now) & " - " & DateTime.GetHour(DateTime.Now) & ":" & DateTime.GetMinute(DateTime.Now) & ":" & DateTime.GetSecond(DateTime.Now))
    Salva.close
   
    StartServiceAtExact(Me, DateTime.Now + 1000 * 60 * 1,True)
    Service.StopAutomaticForeground
End SubRandomly, let's say 2 or 3 times a day the app crashes with the following stacktrace:
			
				B4X:
			
		
		
		05-18 19:17:40.725 27303 27303 E AndroidRuntime: FATAL EXCEPTION: main
05-18 19:17:40.725 27303 27303 E AndroidRuntime: Process: appy.app, PID: 27303
05-18 19:17:40.725 27303 27303 E AndroidRuntime: java.lang.RuntimeException: Unable to start service appy.app.check@ec284f8 with null: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=appy.app/.starter }: app is in background uid UidRecord{db53f29 u0a255 SVC  idle procs:1 seq(0,0,0)}
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3721)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at android.app.ActivityThread.-wrap20(Unknown Source:0)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1793)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:105)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at android.os.Looper.loop(Looper.java:164)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:6809)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
05-18 19:17:40.725 27303 27303 E AndroidRuntime: Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=appy.app/.starter }: app is in background uid UidRecord{db53f29 u0a255 SVC  idle procs:1 seq(0,0,0)}
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1522)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at android.app.ContextImpl.startService(ContextImpl.java:1478)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at android.content.ContextWrapper.startService(ContextWrapper.java:645)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at anywheresoftware.b4a.keywords.Common.StartService(Common.java:884)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand(ServiceHelper.java:211)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at appy.app.check.onStartCommand(check.java:69)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3704)
05-18 19:17:40.725 27303 27303 E AndroidRuntime:     ... 8 moreIs there something that i can do for avoiding that crash?
 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		