-1

I want to call the method of a service 1 in service 2 of same app. For example there is Method1 in service 1.

public void Method1(){
....}

and in service 2 my code will be as...

Service1 serviceOne_object=new Service1();
service1_object.Method1();

But this is not working.

Zoe Shang
  • 51
  • 1
  • 3
  • 1
    Possible duplicate of [How to call methods of a Service from activity?](http://stackoverflow.com/questions/4844930/how-to-call-methods-of-a-service-from-activity) – Shree Krishna May 15 '16 at 07:06

1 Answers1

1

This is not going to work. You can pass data between services using standard android intent mechanism.

Service1:

Intent intent = new Intent(this, Service2.class);
intent.putExtra("call_some_method", true);
startService(intent);

Service2:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if(intent != null && intent.getBooleanExtra("call_some_method", false)) {
        Method1();
    }
}
x0r
  • 1,271
  • 11
  • 13