1

I'm reading through the docs and the more time I spend I get more confused what's the easiest way to accomplish what I'm trying to do. I want to write a simple Service, which starts at button onClick and binds to the activity. And when the activity is closed and started again later (not only restarted!), I want to check whether the service is already running and bind to it. How do I do it?

Thanks

Sebastian Nowak
  • 5,607
  • 8
  • 67
  • 107
  • you don't need to check if the service is running. just bind to it, it will be launched if necessary. – njzk2 Aug 23 '11 at 10:40

2 Answers2

1

In that Scenario I think you only need to use AsyncTask hope this helps

Dev.Sinto
  • 6,802
  • 8
  • 36
  • 54
0

To perform actual binding of services to activities in android, you'll need to extend the Service class and bind the service to your activity ( and possibly use Android's AIDL to perform communication between the activity & service). However, in your example, is sounds like you could get away with just using a separate thread within your activity. Use either a runnable or an AsyncTask. Once the user clicks the button that fire's the onClick, set a static boolean within your application to true. Then, upon re-entry into the activity, simply check that boolean for true and, if true, fire off the thread again.

SBerg413
  • 14,515
  • 6
  • 62
  • 88