Skip to content

A sample to show optimizations in starting a foreground service

Notifications You must be signed in to change notification settings

svvashishtha/ServiceStartExample

Repository files navigation

Foreground Service start optimization

A sample to show an optimal method of starting a foreground service
A common crash related to usage of foreground services is : Context.startForegroundService() did not then call Service.startForeground()

To get rid of this use this strategy :
Instead of starting the service as a foreground service, start the service as a background service, bind to it, then when you have the service instance available in your activity/UI component, you can directly call a method inside the service which calls Service.startForeground() and adds the notification.

This might sound like a hack but think about how music apps like Spotify start their service. This is a similar approach. The results are outstanding. Using this approach the issue count reduced to 0 from a significant unrevealable number.

About

A sample to show optimizations in starting a foreground service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages