After finding there's not any really satisfactory answer to this on StackOverflow or elsewhere I decided to research the (current, 2017) definitive solution.
Here it is:
https://github.com/JamesSmartCell/PersistentWidgetTask.git
This is a demo that shows how to implement a persistent background task that doesn't get shut down, that also shows a very simple implementation of a button in a widget too, another very common design that doesn't receive a lot of good answers.
I looked at a lot of little demos across the internet, the key to this was on the excellent Vogella website here:
http://www.vogella.com/tutorials/AndroidTaskScheduling/article.html
The breakdown is:
- You need to use JobScheduler not AlarmManager
- You need to create a JobService to receive the scheduled job, then call your background service from the JobService onStartJob
In your AndroidManifest file you need to specify:
android:permission="android.permission.BIND_JOB_SERVICE"
I hope this saves someone who is still searching for the answer a lot of time!