How do I make a Android Service where I can pass information to it when it starts?
I wanna start an android service but I need to pass some info to it before it starts how can I do thi开发者_如何学运维s?
There are a few approaches you could take.
Take a look at http://programmerbruce.blogspot.com/2011/04/simple-complete-app-widget-part-1.html for an example of adding a value to the Intent extras, which is then received by an IntentService in onHandleIntent.
Another approach would be to use an AsyncTask, which makes it very easy to provide an arbitrary data structure.
For more ideas, take a look at how Jeff Sharkey's android-sky app handles threading.
精彩评论