The Bible calls David “a man after God's own heart” twice. The first time was by Samuel who anointed him as backslidden King Saul's successor, “But now your kingdom shall not continue. The Lord has sought for Himself a man after His own heart” (1 Sam. 13:14, NKJV)
The youngest son of Jesse, David began his career as an aide at the court of Saul, Israel’s first king. He so distinguished himself as a warrior against the Philistines that his resultant popularity aroused Saul’s jealousy, and a plot was made to kill him. He fled into southern Judah and Philistia, on the coastal plain of Palestine, where, with great sagacity and foresight, he began to lay the foundations of his career.
As an outlaw with a price on his head, David led the life of a Robin Hood on the desert frontier of his tribal domain in Judah (in the south of the Levant). He became the leader and organizer of a group of other outlaws and refugees, who progressively ingratiated themselves with the local population by protecting them from other bandits or, in case they had been raided, by pursuing the raiders and restoring the possessions that had been taken. Those actions eventually ensured that he would be “invited” to become king as the true successor of Saul after the latter was slain in battle against the Philistines on Mount Gilboa.