The thread opener has solved his question himself:
You need to store the return value of the gmap.addTileOverlay() method to a variable and can then call .remove() on it (just as you would with markers):
public class Map {
private TileOverlay tileOverlay;
...
void replaceOverlayTiles() {
TileProvider tileProvider = new UrlTileProvider(256, 256) {
@Override
public URL getTileUrl(int x, int y, int zoom) {
String s = String.format(Locale.GERMANY, "http://www.domain.com/xyz_tiles/%d/%d/%d.png", zoom, x, y);
if (!checkTileExists(x, y, zoom))
return null;
try {
return new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
private boolean checkTileExists(int x, int y, int zoom) {
return !(zoom < 0 || zoom > 20);
}
};
if (tileOverlay != null)
tileOverlay.remove();
tileOverlay = googleMap.addTileOverlay(new TileOverlayOptions().fadeIn(false).tileProvider(tileProvider));
}