sematext/sematext-logsene-android

Exception - Not allowed to start service Intent - caused by startService call

otisg opened this issue · 3 comments

otisg commented

We are getting continuous Fatal exception from our Crashlytics, with a reference to this line in the ExceptionStack...
com.sematext.android.Logsene.sendServiceIntent (SourceFile:143)
Fatal Exception: java.lang.IllegalStateExceptionNot allowed to start service Intent { cmp=com./com.sematext.android.LogseneService (has extras) }: app is in background uid UidRecord{ TRNB idle change:uncached procs:2 proclist:****,18907, seq(0,0,0)} com.sematext.android.Logsene.sendServiceIntent

It seems to be coming from here:

https://stackoverflow.com/questions/46445265/android-8-0-java-lang-illegalstateexception-not-allowed-to-start-service-inten seems to point out there is some change in behaviour in different Android versions and people have shared their solutions.

We should change this and make a new release.

We also ran into this issue, and are working on a fix.

Here's what we are thinking, please let us know if there's any concerns:

  • Move SqliteObjectQueue preflightQueue into Logsene.java, and add JSON objects directly into preflightQueue
  • preflightQueue will be using Application context
  • Make LogWorker extend Worker (WorkManager architecture), and change it to be a one-off task
  • In Logsene.sendServiceIntent(), it will check if minimum batch size or time threshold has been hit, and if so, schedule a LogWorker work request with WorkManager, with some optional constraints such as only when charging, or only on unmetered network.
  • Add a Logsene.flush() call and have applications call it in their onDestroy(), to take care of queued logs in the case that the application crash.

This sounds good @kim-low as mentioned in email. Thanks again for looking into this.

Closing this as the issue should be now fixed with latest 2.0.0 version.