michael
michael

Reputation: 110570

Can I get the instance of the service class that I created

If I create a Service like this:

    Intent intent = new Intent(context, MyService.class);
    context.startService(intent);

Can you please tell me how can my code else where get the instance of that service class that I start? And if i start Service, does that class runs in its own thread?

Thank you.

Upvotes: 2

Views: 1808

Answers (1)

Falmarri
Falmarri

Reputation: 48577

You have to bind to the service.

And the service is started asynchronously, but any code that's run in the service is run on the main thread. In fact, everything in android is run on the main thread unless you specifically create another thread.

Upvotes: 1

Related Questions