0

我有两个服务

  1. 服务A
  2. 服务乙
  3. 服务中心

服务 A 代码:

public class ServiceA extends Service  {


    @Override
public IBinder onBind(Intent arg0) {
    return null;
}

@Override
public void onCreate() {
    super.onCreate();
    testfunction1();
            Thread1();

}

public synchronized void testfunction1(){
    Log.d("Thread","Hi I Am Test 1");
}

public void Thread1(){
    new Thread(new Runnable() {
        public void run() {
            while (true) {
                try {
                    Thread.sleep(5000);

                }catch (InterruptedException e) {
                    e.printStackTrace();
                }
                testfunction1();

            }
          }                        
        }).start();
}

@Override
public void onDestroy() {
    super.onDestroy();
}

服务 B 代码

public class ServiceB extends Service  {


@Override
public IBinder onBind(Intent arg0) {
    return null;
}

@Override
public void onCreate() {
    super.onCreate();
    testfunction2();
            Thread2();
}

public synchronized void testfunction2(){
    Log.d("Thread","Hi I Am Test 2");
}

public void Thread2(){
    new Thread(new Runnable() {
        public void run() {
            while (true) {
                try {
                    Thread.sleep(5000);

                }catch (InterruptedException e) {
                    e.printStackTrace();
                }
                testfunction2();

            }
          }                        
        }).start();
}

@Override
public void onDestroy() {
    super.onDestroy();
}

编辑:添加服务 3

**Service C Code**

    public class ServiceC extends Service  {


    @Override
    public IBinder onBind(Intent arg0) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Intent ServiceA = new Intent("ServiceA Package Name");
        this.startService(ServiceA);
        Intent ServiceB = new Intent("ServiceB Package Name");
        this.startService(ServiceB);
        ServiceA admin = new ServiceA();
        admin.Thread1();
        ServiceB security = new ServiceB();
        security.Thread2();
    }
}

问题是当我运行这两个服务时

它将继续记录

线程你好我是测试 1

线程你好我是测试 1

线程你好我是测试 1

线程你好我是测试 1

线程你好我是测试 1

线程你好我是测试 1

为什么我没有收到 Service 2 日志?

4

0 回答 0