杀不死的服务

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(this, Service1.class);
startService(intent);
}
}


public class Service1 extends Service {

@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}

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

@Override
public void onDestroy() {
Intent intent = new Intent(this,Service2.class);
startService(intent);
super.onDestroy();
}


}

public class Service2 extends Service {

@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}

@Override
public void onDestroy() {
Intent intent = new Intent(this,Service1.class);
startService(intent);
super.onDestroy();
}

}

原文地址:https://www.cnblogs.com/bravolove/p/5007640.html