1

How I can start my service in ASyncTask for example

MyTask task = new MyTask();
startService(new Intent(MainActivity.this, MyService.class),    task);

What is correct way to do this?

I want to tell service in which threads are executed

ksh.max
  • 429
  • 1
  • 5
  • 15

1 Answers1

0

Quote from Android dev. :

AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

I guess if you're not using directly startService, is that you want start it in a new thread, no ? If so, you should do a new thread :

Thread t = new Thread(){
public void run(){
getApplicationContext().bindService(
        new Intent(getApplicationContext(), YOURSERVICE.class),
        serviceConnection,
        Context.BIND_AUTO_CREATE
    );
}
};
t.start();
Goo
  • 1,318
  • 1
  • 13
  • 31