your assumption is correct. if you want no clicks, you have to make sure that the sine wave was generated so that only complete periods are written inside the byte array. otherwise you will cut the wave, which will lead to clicking noises.
for the implementation: you could have a variable "nextPitch", which will become the current pitch as soon as a full period was written.