I need a service to start at boot that periodically checks some database for newly posted data. If there is new data(that fits the correct parameters) I need to then start an activity to display this. I plan on having a notification in-between this to allow the user the choice of dismissing the new data, if they are uninterested or in the middle of some other task. I have some php on a server that I am using to quer开发者_如何学运维y the database, it works but it is in an activity. I have read a lot on here about alarmManagers and broadcast receivers. I think I need a broadcast receiver that starts on boot, that will start the service that will check for updates, then start the activity if there are.
Thanks a lot
To get a start with broadcast receiver take a look here for example.
Get the service implemented. Take a look at IntentService. It offloads the work into a worker thread, so you don't need to care about that yourself.
Schedule the service to start itself periodically using AlarmManager. Don't forget about wake lock to wake the device if needed.
It is usually not a good idea to start any activities without user consent. Show a notification in the notification bar that some new data is available. When user taps on the notification you start the activity to show the data.
There is more to that you just have to start step by step and make it happen :)
Are you asking how to start the service at boot, or start an activity from the service?
For the later android start activity from service , and for the former Android -Starting Service at Boot Time
精彩评论