After setting the current layer extent, you would need to refresh the map display
iface.mapCanvas().refresh()
If you want to do a particular action when the layer is empty, you can count the features
layer.featureCount()
The function would look like:
def exportImages():
i = 1
for j in LAYERS:
sleep(3)
if layerj.featureCount() == 0:
#do something with empty layer... (skip, copy a blank image etc)
else:
#Zoom to layer
iface.mapCanvas().setExtent(j.extent())
iface.mapCanvas().refresh()
# Take screenshot
print("Screen Shotting: " + IMAGE_DIR + FILENAME + str(i) + ".png")
iface.mapCanvas().saveAsImage(IMAGE_DIR + FILENAME + str(i) + ".png")
i = i + 1