java - Start current instance of service in an activity -


i have service this:

public class myservice extends service{     .     .     .     private activity source;     public setactivity(activity source){         this.source=source;     } } 

and activity this:

public class myactivity extends activity{     .     .     .     @override     public void oncreate(bundle savedinstancestate){         .         .         myservice service=new myservice();         service.setactivity(this);         //in place want start service.         //but if use intent, run instance of service.         intent intent = new intent(this,myservice.class);         startservice(intent);     } } 

how start current instance service? in place want start service.

it's not idea keep instance of activity inside service.

android guides :

a service application component can perform long-running operations in background , not provide user interface.

you can start service in background intents.

intent intent = new intent(this,myservice.class); startservice(intent); 

if attempt response service, checkout tutorials related service better understanding of it.