By living among the Philistines, David found a way to get away from Saul. Of course, the disadvantage to living among the Philistines is that you have to live among the Philistines. David got around that by getting his own city, with two results. First, he was able to use it to destroy Canaanites. Second, because David wasn't directly under this king's eye, he could lie and say he was attacking Israelite villages.
David was a great warlord and psalmist, but he was also extremely smart.