0

I want to start a service from an activity. The activity keeps on doing its own work even after calling the service. So, I have used AsyncTask to start the service. But my service does not start until the main thread stops executing. My services uses an instace of WindowManager. Is it possible to run both the service and the activity simultaneously? I tried creating a separate thread for the service and also tried BrodcastReceiver but the service started only after the activity finished doing its job.

nkr
  • 118
  • 1
  • 8
  • put your startservice code into onPostExecute() method – Dixit Patel Jun 12 '13 at 11:42
  • I tried, but again the service starts after the activity finishes.. – nkr Jun 12 '13 at 11:46
  • have u register service in manifest – Dixit Patel Jun 12 '13 at 11:48
  • yes the service is registered. Actually it runs fine but cannot run simulataneously with the activity... – nkr Jun 12 '13 at 11:51
  • Where are you starting the service from? which Activity method? e.g. onCreate(). Are you blocking the Main UI thread while waiting for the service to start? You need to let the Main UI activity continue and show some sort of UI e.g. progress while you wait for service to start. Once started your activity should get a call to bindService() – quickdraw mcgraw Jun 12 '13 at 12:34
  • @quickdrawmcgraw: The onCreate() of the activity calls a method. From that method, the service is started. I am not blocking the Main UI while waiting for the service to start. I want to keep the main UI running forever and to start/stop the service from it. The service should run parallel to the activity. – nkr Jun 12 '13 at 12:47
  • You said, the activity keeps on doing its own work. What kind of work? Could you add that code and the method, in which you start the service? – Torben Kohlmeier Jun 12 '13 at 13:44

0 Answers0